Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO POPULATE A FIELD IN THE DESTINATION TABLE

Status
Not open for further replies.

sgp_imported

Technical User
Sep 11, 2001
8
0
0
US
WITH NO CORRESPONDING FIELD IN THE SOURCE TABLE.

I.E. "A" TO BE POPULATED IN THE FIELD "ORG" IN THE DESTINATON TABLE, STANDING FOR ORGANIZATION A.

So when pumping data from multiple databases with the same file structure into one table, I want to id the organiztion from which the records are from.

ORDER# ORDER DATE ORG
12345 05/30/03 A

THANK YOU!
 
insert into newtable
(order#,orderdate,org)
select
order#,orderdate,'A'
from oldtable



 
I realized that was not as clear as it should of been.

Instead of just pulling the data from the source table, use dts to run the query above on the source table.
 
This thread helped me already, but I want to make sure I can do something in addition to what is already listed. If I take the code listed:

insert into Table1
(order#, orderdate, org)
select order#, orderdate, org
from OldTable

Can I then add WHERE clauses? For instance, if I'm looking for for a specific date in orderdate, can I "add-on" the following code?:

WHERE datepart (dd, orderdate) = 16
and datepart (mm, orderdate) = 9
and datepart (yy, orderdate) = 2003

Thanks for any suggestions!
 
T3le - yes you can filter the data you are inserting. Your where clause will work, but if you are only looking for one specific date, it is faster & easier just to do this:
WHERE orderdate = '9/16/2003'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top