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 |
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2008-08-06 : 18:32:31
|
| Hi.I've wrote this Query:SELECT DISTINCT cat_level2_idFROM dbo.tbl_cat_relationWHERE (cat_level3_id NOT IN (SELECT tbl_configurator.cat_level2_id FROM tbl_configurator))the result shows me 127 rows in tbl_configurator which I dont have any cat_level2_id on tbl_relation.now I want a query to insert those 127 rows to tbl_relation.thank u so much 4 yr help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-07 : 02:29:53
|
quote: Originally posted by a.ashabi Hi.I've wrote this Query:SELECT DISTINCT cat_level2_idFROM dbo.tbl_cat_relationWHERE (cat_level3_id NOT IN (SELECT tbl_configurator.cat_level2_id FROM tbl_configurator))the result shows me 127 rows in tbl_configurator which I dont have any cat_level2_id on tbl_relation.now I want a query to insert those 127 rows to tbl_relation.thank u so much 4 yr help.
what you're checking above is just oppoiste. The query is looking for cat_level2_id values in tbl_relation which are not in tbl_configurator.What you're asking for is thisINSERT INTO tbl_relation (cat_level2_id)SELECT c.cat_level2_idFROM tbl_configurator cLEFT JOIN tbl_relation rON r.cat_level2_id=c.cat_level2_idWHERE r.cat_level2_id IS NULL |
 |
|
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2008-08-07 : 05:09:51
|
| thank u again.worked :) |
 |
|
|
|
|
|