Author |
Topic |
kwacz23
Starting Member
44 Posts |
Posted - 2013-09-19 : 02:38:52
|
HiI have data likeorder_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. |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-09-19 : 03:01:10
|
My Guess Is ,select Distinct Order_number from tablename where PoNumber = 'Null_Value' and Order_Number = 1veeranjaneyulu |
|
|
Dineshkumar89
Starting Member
2 Posts |
Posted - 2013-09-19 : 03:05:20
|
Declare @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 @tablewhere PONumber LIKE '%NULL_VALUE%'Regardsdineshkumar |
|
|
Dineshkumar89
Starting Member
2 Posts |
Posted - 2013-09-19 : 03:07:47
|
here it is,Declare @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%')Regardsdineshkumar |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-19 : 03:15:53
|
You can get the order numbers which has NO PONumber by using following query...........SELECT order_numberFROM @tablegroup by order_numberhaving count(*) = count(CASE WHEN PONumber = 'NULL_Value' then order_number END)--Chandu |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-19 : 03:34:44
|
quote: Originally posted by VeeranjaneyuluAnnapureddy My Guess Is ,select Distinct Order_number from tablename where PoNumber = 'Null_Value' and Order_Number = 1veeranjaneyulu
By looking at sample data you can do the above where condition...For actual data how OP will get to know the order_number which has NO PONumber?--Chandu |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-19 : 04:29:52
|
SELECT Order_NumberFROM dbo.Table1GROUP BY Order_NumberHAVING MIN(PONumbe) IS NULL Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-19 : 04:29:53
|
SELECT Order_NumberFROM dbo.Table1GROUP BY Order_NumberHAVING MIN(PONumbe) IS NULL Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-09-19 : 09:11:31
|
SELECT Top(1) Order_NumberFROM Temp1GROUP BY Order_NumberHAVING MIN(PONumber) IS NOT NULLveeranjaneyulu |
|
|
kwacz23
Starting Member
44 Posts |
Posted - 2013-09-19 : 10:25:24
|
thanks for your all reply. 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....) |
|
|
|