34,590
社区成员
发帖
与我相关
我的任务
分享
select New_Date,
case when DateDiff(d,GETDATE(),New_Date)<7 then 0 else 1 end as px
into #test--将查询的结果放到临时表#test
from(
select case when A.date1 is null then A.date2 else A.date1 end as New_Date
from table A
)t
select New_Date from #test order by px
select * from(
select (case when A.date1 is null then A.date2 else A.date1 end) as New_Date from table A
)t
order by (case when DateDiff(d,GETDATE(),New_Date)<7 then 0 else 1 end) asc
select (case when A.date1 is null then A.date2 else A.date1 end) as New_Date from [table] A
order by 1 asc
go
create view view_temp
as
select New_Date,
case when DateDiff(d,GETDATE(),New_Date)<7 then 0 else 1 end as px
from(
select case when A.date1 is null then A.date2 else A.date1 end as New_Date
from table A
)t
--创建以上试图吧
--调用语句
select New_Date from view_temporder by px