这是ACC语句: SELECT 证照情况.*, IIf([证照情况.到期日期]-Date() Is Null,"不确定",IIf([证照情况.到期日期]-Date()<=0,"过期",IIf([证照情况.到期日期]-Date()<=90,"快过期","正常"))) AS 状态
FROM 证照情况;
转到SQL2000视图查询语句怎么写。我改半天都是提示函数不对,请高手帮助解决,谢谢
FROM 证照情况;
转到SQL2000视图查询语句怎么写。我改半天都是提示函数不对,请高手帮助解决,谢谢
select 证照情况.*,
case when [证照情况.到期日期]-Date() Is Null then '不确定'
when [证照情况.到期日期]-Date()<=0 then '过期'
when [证照情况.到期日期]-Date()<=90 then '快过期'
else '正常' end as 状态
FROM 证照情况
as
SELECT 证照情况.*,
case when datediff(dd,证照情况.到期日期,getdate()) < 0 then '不确定'
when datediff(dd,证照情况.到期日期,getdate()) > 0 then '过期',
when datediff(dd,证照情况.到期日期,getdate()) <= 90 '快过期'
end AS 状态
FROM 证照情况;你自己把时间那里更改一下,不太明确你具体的意思.
我的意思是[证照情况]表里有个日期字段是[到期日期],当这个字段里的数据和当前日期比较时,如果 [当期日期]里某数据为空时,在新添加的字段[状态]里显示‘不确定' ,如果[期日期]-Date()<=0,在新添加的字段[状态]里显示‘过期' ;如果[期日期]-Date()<= 90,在新添加的字段[状态]里显示‘快过期',如果[期日期]-Date()>90,新添加的字段[状态]里显示‘正常'
else (case when datediff(dd,getdate(),[证照情况.到期日期])<=90 then '快过期' else '正常' end)end) AS 状态
FROM 证照情况
declare @证照情况 table (证照编号 int,到期日期 datetime)
insert into @证照情况
select 1,'2011-02-01' union all
select 2,'2011-09-12' union all
select 3,'2010-10-12' union all
select 4,null union all
select 5,'2010-12-01'SELECT a.*,
case when a.到期日期 is null then '不确定'
when datediff(dd,getdate(),a.到期日期) < 0 then '过期'
when datediff(dd,getdate(),a.到期日期) <= 90 then '快过期' else '正常'
end AS 状态
FROM @证照情况 a/*
证照编号 到期日期 状态
----------- ----------------------- ------
1 2011-02-01 00:00:00.000 快过期
2 2011-09-12 00:00:00.000 正常
3 2010-10-12 00:00:00.000 过期
4 NULL 不确定
5 2010-12-01 00:00:00.000 过期
*/
create view yourview
as
SELECT a.*,
case when a.到期日期 is null then '不确定'
when datediff(dd,getdate(),a.到期日期) < 0 then '过期'
when datediff(dd,getdate(),a.到期日期) <= 90 then '快过期' else '正常'
end AS 状态
FROM 证照情况 a--查询视图
select * from yourview--得到结果
/*
证照编号 到期日期 状态
----------- ----------------------- ------
1 2011-02-01 00:00:00.000 快过期
2 2011-09-12 00:00:00.000 正常
3 2010-10-12 00:00:00.000 过期
4 NULL 不确定
5 2010-12-01 00:00:00.000 过期
*/
insert into 证照情况 select 1,null
union all select 2,'2010-08-10'
union all select 3,'2011-01-15'
union all select 4,'2011-10-01'
go
SELECT 证照情况.*, (case sign(datediff(dd,getdate(),到期日期)) when Null then '不确定' when -1 then '过期'
else (case when datediff(dd,getdate(),到期日期)<=90 then '快过期' else '正常' end)end) AS 状态
FROM 证照情况
go
drop table 证照情况
/*
证照编号 到期日期 状态
----------- ----------------------- ------
1 NULL 正常
2 2010-08-10 00:00:00.000 过期
3 2011-01-15 00:00:00.000 快过期
4 2011-10-01 00:00:00.000 正常(4 行受影响)
*/
弄成功了