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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-11-16 : 09:46:32
|
Hi,Here are two separate sql queries.They get the records which are available in one table but not in the other...1)insert into tblMainselect ...from @tbl1 left join @tbl2 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where @tbl2.field1 IS NULL AND @tbl2.field2 IS NULL2)insert into tblMainselect...from @tbl2 left join @tbl1 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where @tbl1.field1 IS NULL AND @tbl1.field2 IS NULL Question:How can the above two queries be joined into one sql?Thanks |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-11-16 : 10:22:48
|
[code]insert into tblMainselect ...from @tbl1 left join @tbl2 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where @tbl2.field1 IS NULL AND @tbl2.field2 IS NULLUNION ALLselect...from @tbl2 left join @tbl1 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where @tbl1.field1 IS NULL AND @tbl1.field2 IS NULL[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-16 : 10:28:16
|
| [code]insert into tblMainselect...from @tbl2 full outer join @tbl1 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where ((@tbl1.field1 IS NULL AND @tbl1.field2 IS NULL) OR (@tbl2.field1 IS NULL AND @tbl2.field2 IS NULL))[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-11-16 : 10:46:06
|
| Thanks |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-11-16 : 10:50:39
|
quote: Originally posted by visakh16
insert into tblMainselect...from @tbl2 full outer join @tbl1 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where ((@tbl1.field1 IS NULL AND @tbl1.field2 IS NULL) OR (@tbl2.field1 IS NULL AND @tbl2.field2 IS NULL)) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Now the passage ... is interesting isn't it? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-16 : 12:16:12
|
quote: Originally posted by webfred
quote: Originally posted by visakh16
insert into tblMainselect...from @tbl2 full outer join @tbl1 on @tbl1.field1 = @tbl2.field1 and @tbl1.field2 = @tbl2.field2where ((@tbl1.field1 IS NULL AND @tbl1.field2 IS NULL) OR (@tbl2.field1 IS NULL AND @tbl2.field2 IS NULL)) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Now the passage ... is interesting isn't it? No, you're never too old to Yak'n'Roll if you're too young to die.
Sorry I lost you------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|