我需要确定哪些寄存器即将过期。我有一半的脚本显示即将到期的脚本,但我需要保存最终日期:
declare @FechaIngreso datetime --Variable to determinate begin
declare @FechaEgreso datetime --Variable End
declare @DiasExp Int --Days before Expire
set @DiasExp = 10
select @FechaIngreso = GETDATE() --Get the actual date
select @FechaEgreso = (select top 1 FEC_FINA from FA_DDERI where (DATEDIFF (dd, @FechaIngreso,FEC_FINA) ) = @DiasExp ) --heres the thing I select just 1 with top 1 cause I need save the final date to comparate the dates
select * from FA_DDERI where FEC_FINA = @FechaEgreso
select COUNT(*) from FA_DDERI where FEC_FINA = @FechaEgreso --this tell me how many lines get the condition
我需要以下条件:
if (select FEC_FINA from FA_DDERI where (DATEDIFF (dd, @FechaIngreso,FEC_FINA) ) = @DiasExp)
print 'The Reso Will Expire'
break
else
continue
print'Any Reso will Expire'
这些表只有1个唯一列,而且它不是标识列
是否有控制语句来检查数据库中的每一行以证明条件?
答案 0 :(得分:0)
我想你想要这个
SELECT FEC_FINA,
CASE
WHEN DATEDIFF (dd, @FechaIngreso,FEC_FINA) ) = @DiasExp THEN 'The Reso Will Expire'
ELSE 'Any Reso will Expire'
END AS resultcol
FROM FA_DDERI