Sql Select 0 1 0 1 sequence from database table

215 views Asked by At

I need to fetch output from given below table in 0 1 0 1 sequence .All other data at the end of table.

create table #Temp
(
    EventID INT IDENTITY(1, 1) primary key ,
    Value bit
)
INSERT  INTO  #Temp(Value) Values
(0),(1)
,(0),(0)
,(0),(0)
,(0),(0)
,(1),(1)
,(1),(1)
,(1),(0)
,(0),(0)
,(1),(1)
,(0),(1)
1

There are 1 answers

1
dnoeth On BEST ANSWER

This is probably what you want:

select *
from #Temp
order by row_number() over (partition by Value order by EventID), Value