all groups > sql server new users > august 2005 >
You're in the

sql server new users

group:

Inserting columns from one table into another



Re: Inserting columns from one table into another Hugo Kornelis
8/25/2005 12:00:00 AM
sql server new users: [quoted text, click to view]

Hi Korina,

What were the results from this statement? How did they differ from what
you expected?

In order to help us help you, please post the following:
* CREATE TABLE statements for both tables involved, including all
constraints and properties - you may omit irrelevant columns;
* some INSERT statements with sample data;
* the output you expect from the sample data provided.
See www.aspfaq.com/5006 for more details.

Best, Hugo
--

Inserting columns from one table into another Korina B
8/25/2005 9:29:05 AM
I currently have 2 tables. Both have ssn's of an employee. I'm trying to
pull 2 fields, de_code and amount, from one of the tables based on the ssn
and the de_code like EIC (which is just a value in de_code). I'm having
trouble merging those 2 fields into the other table. Should I instead create
a new table with all the data? Any help would be greatly appreciated. I know
there is data that matches in both tables but it isn't pulling anything.

For example the tables with the following fields
TABLE1:
emp_ssn, name, address, city, state, zip, de_code

TABLE2:
emp_ssn, check_no, de_code, amount


This is a statment I tried.
SELECT TABLE1.emp_ssn,
TABLE1.name,
TABLE1.address,
TABLE1.city,
TABLE1.state,
TABLE1.zip,
TABLE2.de_code,
TABLE2.check_no,
TABLE2.amount
FROM TABLE1, TABLE2
where TABLE1.emp_ssn = TABLE2.emp_ssn AND de_code like'%EIC%'
RE: Inserting columns from one table into another Chandra
8/25/2005 10:58:17 AM
hi korina
the query looks good!

there might be some spaces in the ssn field:

so use the query as:
SELECT TABLE1.emp_ssn,
TABLE1.name,
TABLE1.address,
TABLE1.city,
TABLE1.state,
TABLE1.zip,
TABLE2.de_code,
TABLE2.check_no,
TABLE2.amount
FROM TABLE1, TABLE2
where RTRIM(LTRIM(TABLE1.emp_ssn)) = RTRIM(LTRIM(TABLE2.emp_ssn)) AND
de_code like'%EIC%'

if u still have a problem, just paste the table content so that i can give u
a better solution

please let me know if u have any questions

--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---------------------------------------



[quoted text, click to view]
AddThis Social Bookmark Button