【发布时间】:2012-10-10 18:31:20
【问题描述】:
我有以下表架构
declare @temp table
(
id int identity(1,1) not null,
nod nvarchar(50)
)
其中nod 列有以下数据
insert into @temp select 'N/A'
insert into @temp select 'N/A'
insert into @temp select '5'
insert into @temp select 'N/A'
insert into @temp select '7'
insert into @temp select 'N/A'
insert into @temp select '31'
insert into @temp select '15'
我希望选择语句在以下基础上给我结果
如果nod 值'N/A' 那么它应该显示'N/A'
或者如果有像 5,15,31 这样的数值,那么它应该显示 getdate()-nod date 日期列
我已尝试关注但未能减去天数,并且当 'N/A' 在该 nvarchar 列中时也代表 'N/A'
select DATEADD(dd,case nod when 'N/A' then 0 else nod end,GETDATE()) from @temp
【问题讨论】: