order by ( case when CONVERT(varchar(8),GETDATE(),112) < bsdt then 2 when CONVERT(varchar(8),GETDATE(),112) between replace(bsdt,'-','') and replace(bedt,'-','') then 1 when CONVERT(varchar(8),GETDATE(),112) > bedt then 5 when CONVERT(varchar(8),GETDATE(),112) between replace(sdt,'-','') and replace(edt,'-','') then 3 when CONVERT(varchar(8),GETDATE(),112) < bedt then 4 end ) , bsdt desc
2024-07-18
select * from TBL_CODE where code='AB1' order by code asc