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 |
|
steamngn
Constraint Violating Yak Guru
306 Posts |
Posted - 2009-05-09 : 15:51:14
|
Hi all,I have a table with two columns like so:STK_LOC_ID | LOC_GRP_ID-----------------------NULL | MOBILEREMOTE | MOBILEMAIN | TESTGROUPREMOTE | TESTGROUP What I need to do is select distinct(loc_grp_id)where stk_loc_id does not have NULL IE return just TESTGROUP.Can someone give some insight for me?TIA,AndyThere's never enough time to type code right, but always enough time for a hotfix... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-09 : 16:13:50
|
select loc_grp_idfrom table1group by loc_grp_idhaving max(case when stk_loc_id is null then 1 else 0 end) = 0 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
steamngn
Constraint Violating Yak Guru
306 Posts |
Posted - 2009-05-09 : 16:20:58
|
| Peso!I haven't posted on this site in quite some time, and the last time I did you saved the day for me! Now again I tip my hat to your eloquent and functioning code!Thank you!AndyThere's never enough time to type code right, but always enough time for a hotfix... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-09 : 19:25:24
|
Thenk you for the feedback. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-10 : 02:35:06
|
Another methodSELECT DISTINCT t.LOC_GRP_IDFROM YourTable tOUTER APPLY (SELECT COUNT(*) AS NullCnt FROM YourTable WHERE LOC_GRP_ID=t.LOC_GRP_ID AND STK_LOC_ID IS NULL) t1WHERE ISNULL(NullCnt,0)=0Alsoselect loc_grp_idfrom table1group by loc_grp_idhaving count(*) - count(STK_LOC_ID)=0 |
 |
|
|
|
|
|