sql server new users:
[quoted text, click to view] On Thu, 25 Aug 2005 09:29:05 -0700, Korina B wrote: >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%'
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 --
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%'
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] "Korina B" wrote: > 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%'
Don't see what you're looking for? Try a search.
|