Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Doubt in writing Insert stmt

Author  Topic 

testac
Starting Member

3 Posts

Posted - 2009-10-18 : 14:10:37
I have 3 Table say TableA(holding data) ,TableB(mapping data) and TableC(data to be inserted).

TableA
Col1
----
High
High
Low
Right
Low
Left

TableB
Col1 Col2
-----------------
1 High
2 Low
3 Left
4 Right

Table
Col1
----
1
1
2
4
2
3

My Dataset is like 3 tables shown above.
TableA consists of source data uploaded using bcp.

TableB is a mapping table with static reference values as you can see.

TableC is the table to which now data has to be inserted which is col1 of TableB and equivalent numeric value for Col1 in TableA.

So my doubt is how I write so that I write my insert script for TableC
and resolve corresponding values for Col1 in TableA.
in short I want numeric equivalent of Col1 in TableA to be inserted into TableC by checking on mapping values rom TableB.

Thanks in advance

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-18 : 14:20:35
Try this:
insert tableC
select
tableB.col1
from tableA
join tableB on tableB.Col2 = tableA.Col1


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -