473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple table data retrieval into separate table

1 New Member
Greetings,

I have an empty table in which i want to populate using data from another table. The following query will only populate the "CASH" column in the destination table, however, i need to populate 2 others columns in the same query by changing the WHERE clause criteria. The following query works for part of my problem:

INSERT [HU_TEST].DBO.CLIENT_DETAIL
(CLIENT_ID,
CASH)
SELECT [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ACCOUNTNUMBER,
SUM(DBO.E2E_POSSUM.TOTALVALUE) AS CASH
FROM [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM
WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA')))
GROUP BY DBO.E2E_POSSUM.ACCOUNTNUMBER

However, I have two more columns i need to populate at the same time, the only that changes in order to obtain the correct value is that the line that states:
WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA')))
Will change to :
WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA','EQ')))


Any help would be greatly appreciated.

Thanks in advance.

Michael Smith
Dec 26 '07 #1
1 1189
ck9663
2,878 Recognized Expert Specialist
Greetings,

I have an empty table in which i want to populate using data from another table. The following query will only populate the "CASH" column in the destination table, however, i need to populate 2 others columns in the same query by changing the WHERE clause criteria. The following query works for part of my problem:

INSERT [HU_TEST].DBO.CLIENT_DETAIL
(CLIENT_ID,
CASH)
SELECT [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ACCOUNTNUMBER,
SUM(DBO.E2E_POSSUM.TOTALVALUE) AS CASH
FROM [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM
WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA')))
GROUP BY DBO.E2E_POSSUM.ACCOUNTNUMBER

However, I have two more columns i need to populate at the same time, the only that changes in order to obtain the correct value is that the line that states:
WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA')))
Will change to :
WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA','EQ')))


Any help would be greatly appreciated.

Thanks in advance.

Michael Smith
this query will store the sum(TOTALVALUE) for all records where ASSET = 'CA' or 'EQ'. CASH_CA will contain sum(TOTALVALUE) for ASSET = 'CA' only. CASH_EQ will contain sum(TOTALVALUE) for ASSET = 'EQ' only. you can rename these fields accordingly.

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT [HU_TEST].DBO.CLIENT_DETAIL
  3. (CLIENT_ID, CASH, CASH_CA, CASH_EQ)
  4.  
  5. SELECT [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ACCOUNTNUMBER,
  6. SUM(DBO.E2E_POSSUM.TOTALVALUE) AS CASH,
  7.  
  8. SUM(
  9.    case when [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET = 'CA' then
  10.       DBO.E2E_POSSUM.TOTALVALUE
  11.    else
  12.  
  13.    end
  14.    ) AS CASH_CA,
  15.  
  16. SUM(
  17.    case when [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET = 'EQ' then
  18.       DBO.E2E_POSSUM.TOTALVALUE
  19.    else
  20.  
  21.    end
  22.    ) AS CASH_EQ
  23. FROM [HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM
  24. WHERE ((([HU190-PORTFOLIOCENTER].DBO.E2E_POSSUM.ASSET) IN ('CA', 'EQ')))
  25. GROUP BY DBO.E2E_POSSUM.ACCOUNTNUMBER
  26.  
  27.  
-- CK
Dec 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lyle H. Gray | last post by:
We load a table from a text file using Data Transformation Services. The source file is already sorted by primary key order. After the DTS load, the default retrieval order on the target table...
1
by: Mats Kling | last post by:
Hi all, We are logging approx. 3 million records every day into a history table. Last week we ran into the 64 GB limit in UDB 8 so we recreated the table with 8 k pagesize to get some...
0
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
9
by: AnandaSim | last post by:
Hi All, I've had Access 97, 2000 connections to the corporate Oracle database for a few years now - but seldom use it. When I did use it years ago, performance was not fast but the features were...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
10
by: Doug Bell | last post by:
Hi, I have an application that has a "Data Access Class" and "User Interface Class". It is for receiving Purchase Order data from one system and pushing processed transactions to another...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.