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 |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-12 : 09:44:15
|
| My two tables both have the same field names. The table names are:Diaries and TestIn Diaries I have 141 records. In Test I have 131 records. I want to compare the two tables so I can see which records I'm missing so I can fix my stored procedure. How do I go about writing this?The field names in both tables are:doc, totmet, totclr, weekdat, dowrdat |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 10:02:03
|
Wait until Charlie is coming up because I will go and get a coffee No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-12 : 10:04:27
|
| Okay thanks. I just want to see the records that are missing from the Diaries Table. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 10:17:06
|
select * from Diaries dLEFT join Test ton t.doc = d.docand t.totmet = d.totmetand d.totclr = d.totclrand d.weekdat = d.weekdatand d.dowrdat = t.dowrdatwhere t.doc is null 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 - 2010-05-12 : 10:26:51
|
Also:-select d.* from Diaries dWHERE NOT EXISTS(SELECT 1 FROM Test tWHERE t.doc = d.docand t.totmet = d.totmetand t.totclr = d.totclrand t.weekdat = d.weekdatand t.dowrdat = d.dowrdat) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-12 : 10:27:46
|
quote: Originally posted by webfred select * from Diaries dLEFT join Test ton t.doc = d.docand t.totmet = d.totmetand d. t.totclr = d.totclrand d. t.weekdat = d.weekdatand d.dowrdat = t.dowrdatwhere t.doc is null No, you're never too old to Yak'n'Roll if you're too young to die.
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-12 : 10:34:18
|
| THANKS!!! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-12 : 10:36:21
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|