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 |
|
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2008-05-29 : 12:05:35
|
| Hi i've to table where i have a product code and a area code.I want to insert the values from table 1 into table 2 if the product code and area code do not already exists in the table in table 2.Am using this code below but it does not seem to be working.select distinct p_code1, area_codefrom table1where not exists (select p_code, area_code from table 2 ) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-29 : 12:23:09
|
| [code]Insert into table2 (product_code ,area_code)select distinct p_code1, area_codefrom table1 t1left join table2 t2on t2.p_code=t1.p_code1and t2.area_code=t1.area_codewhere t2.p_code is nulland t2.area_code is null[/code]or [code]select distinct p_code1, area_codefrom table1 t1where not exists((select p_code, area_codefrom table2 where p_code=t1.p_code1and area_code=t1.area_code)[/code] |
 |
|
|
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2008-05-30 : 04:19:48
|
| Thanks i got it to work i did not think of the where part in the query.. |
 |
|
|
|
|
|