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 |
|
duhaas
Constraint Violating Yak Guru
310 Posts |
Posted - 2006-09-13 : 10:34:20
|
| I have the following union:select *from Snapsrawwhere (Branchstate = 'Arizona') and sicid is not null and sicid <> '99' and sectorid <> '100' and (monthend = '20060801')unionSELECT *FROM SnapsRawWHERE (Branchstate = 'Arizona') and (sectorid = '100' or sicid is null) and (Sicdescription is null) and (monthend = '20060801')I want to than say, take those accountnumbers that come back in the results (1449 rows)and show me the accounts that show up in the following query but not in the union queryselect accountidfrom Snapsrawwhere (Branchstate = 'Arizona') and (monthend = '20060801')This query comes back with (1509) so basically I want to know the 60 records that dont show up in my union, just not sure how to build the subquery using the union. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-09-13 : 10:43:06
|
| select a.accountidfrom(select accountidfrom Snapsrawwhere (Branchstate = 'Arizona') and (monthend = '20060801')) bleft join (select *from Snapsrawwhere (Branchstate = 'Arizona') and sicid is not null and sicid <> '99' and sectorid <> '100' and (monthend = '20060801')unionSELECT accountidFROM SnapsRawWHERE (Branchstate = 'Arizona') and (sectorid = '100' or sicid is null) and (Sicdescription is null) and (monthend = '20060801')) bon a.accountid = b.accountidwhere b.accountid is null==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|