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 |
kwacz23
Starting Member
44 Posts |
Posted - 2013-09-22 : 13:58:11
|
HiI have data like (this is only the sample, In fact there are 6000 lines)order_number PONumber1 NULL_Value1 NULL_Value2 AAA2 NULL_Value3 AAA3 AAAI would like to display only orders which have only NULL values.So the results should be only order 1 because order two contants one 'NULL_value' and order 3 not contain.Last time I got two replay :SELECT Top(1) Order_NumberFROM Temp1GROUP BY Order_NumberHAVING MIN(PONumber) IS NOT NULLDeclare @table table (order_number int, PONumber varchar(50))insert into @tableSELECT 1, 'NULL_Value' union ALLSELECT 1, 'NULL_Value' union ALLSELECT 2, 'AAA' union ALLSELECT 2, 'NULL_Value' union ALLSELECT 3, 'AAA' union ALLSELECT 3, 'AAA' select * from @table awhere NOT EXISTS(SELECT * from @table bwhere a.order_number = b.order_numberand PONumber not LIKE '%NULL_VALUE%')However I still have issue because One one order contains NULl_values and poNumber I do not want to any line from this order.I would expect all orders which only have NULL ( 1 or 2 or 3 so on....) |
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-09-22 : 14:13:30
|
select order_numberfrom @tablegroup by order_numberhaving max(case when ponumber <> 'NULL_VALUE' then 1 else 0 end) = 0 |
|
|
kwacz23
Starting Member
44 Posts |
Posted - 2013-09-22 : 14:15:56
|
Thanks a lot for help |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-09-23 : 01:21:13
|
Why do you store NULL_VALUE as a string. You can just NULL (without single quotes) and do select order_numberfrom @tablegroup by order_numberhaving max(case when ponumber is not NULL then 1 else 0 end) = 0Alternatively you can useselect order_numberfrom @tablegroup by order_numberhaving max(ponumber) is NULL and min(ponumber) is NULLMadhivananFailing to plan is Planning to fail |
|
|
|
|
|