Tuesday, December 2, 2014

SQL View: Show NULL until all "orders" have the same "orderstate"


create table test (tid int identity(1,1), OrderID int, OrderSTATE bit)
Insert into test values(1,null),(1,0),(1,1),(2,1),(2,1),(3,0),(3,1)


select OrderID, Case WHEN max(Cast(OrderState as int))= 1 and Min(Cast(OrderState as int))=1 Then 1 Else NULL END as Orderstate from test
Group by OrderID


drop table test


No comments:

Post a Comment