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 |
|
dmikester1
Starting Member
2 Posts |
Posted - 2008-09-30 : 10:50:57
|
| This is complicated for me anyways. Here is the query I am trying to run: SELECT PRPID, count(PRPID) as countP, TDCVPG FROM TASDOCUMENT WHERE TDCNUM = '' AND TDCVPG <> '' AND COUNT(PRPID) > 1 GROUP BY PRPID I want to show all records where TDCNUM is null, TDCVPG is not null and there is more than one of the same PRPID. Does this make sense?ThanksMike |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-09-30 : 10:55:45
|
quote: Originally posted by dmikester1 This is complicated for me anyways. Here is the query I am trying to run: SELECT PRPID, count(PRPID) as countP,TDCVPG FROM TASDOCUMENTWHERE TDCNUM is null AND TDCVPG is not null GROUP BY PRPID ,TDCVPGHaving count(PRPID)>1I want to show all records where TDCNUM is null, TDCVPG is not null and there is more than one of the same PRPID. Does this make sense?ThanksMike
|
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-30 : 11:01:46
|
Just in case NULL should be treated the same way as en empty string, and just in case prpID could be NULL.SELECT prpID, COUNT(*) as countPFROM tasDocumentWHERE (tdcNum IS NULL OR tdcNum = '') AND tdcVpg > ''GROUP BY prpIDHAVING COUNT(*) > 1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
dmikester1
Starting Member
2 Posts |
Posted - 2008-09-30 : 11:03:32
|
quote: Originally posted by sodeep
quote: Originally posted by dmikester1 This is complicated for me anyways. Here is the query I am trying to run: SELECT PRPID, count(PRPID) as countP,TDCVPG FROM TASDOCUMENTWHERE TDCNUM is null AND TDCVPG is not null GROUP BY PRPID ,TDCVPGHaving count(PRPID)>1I want to show all records where TDCNUM is null, TDCVPG is not null and there is more than one of the same PRPID. Does this make sense?ThanksMike
Thanks for the fast reply. That doesn't work because I can't group by TDCVPG because those values are all different. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-30 : 11:04:51
|
[code]DECLARE @Sample TABLE ( prpID INT, tdcNum INT, tdcVpg INT )INSERT @SampleSELECT 1, NULL, 1 UNION ALLSELECT 1, NULL, 2 UNION ALLSELECT NULL, NULL, 1 UNION ALLSELECT NULL, NULL, 2-- sodeepSELECT prpID, COUNT(prpID) as countPFROM @SampleWHERE tdcNum IS NULL AND tdcVpg IS NOT NULLGROUP BY prpID, tdcVpgHAVING COUNT(prpID) > 1-- PesoSELECT prpID, COUNT(*) as countPFROM @SampleWHERE (tdcNum IS NULL OR tdcNum = '') AND tdcVpg > ''GROUP BY prpIDHAVING COUNT(*) > 1[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|
|