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.
| Author |
Topic |
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2012-07-04 : 09:34:11
|
| I need to insrt multiple row in a table.But before inserting rows to that table i have to check if any of the row is present in that final table or not. Now if i have two rows and among these two one is already inserted in the final table then how can i check that and insert another row in the final table with out using any loop condition.i am using IF NOT EXISTS but it will return true if any of the row among the two rows is there in the final table.Ex: i have two record A and B. My final table is TEST.Now if A is there in the table TEST already then how can i check and then insert B row in the table TEST.Is there any way to do this without using cursor or temp table or any other looping condition?Please help...kalyan Ashis Dey |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-07-04 : 09:41:02
|
instead of IF NOT EXISTS you should useinsert TEST(col1, col2)select col1, col2 from Sourcetable t2WHERE NOT EXISTS(select * from TEST t1 where t1.col1 = t2.col1) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2012-07-04 : 10:09:03
|
| THANKS FOR YOU HELP. :)BUT HERE IN MY SOURCE TABLE I DON'T HAVE THE SAME COL AS MY FINAL TABLE. SO NOT ABLE TO DO THE ABOVE.ANY OTHER WAY OUT?kalyan Ashis Dey |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-07-04 : 10:16:10
|
You have stated that you are able to use IF NOT EXISTS so I believe you are able to use WHERE NOT EXISTS No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|