22,182
社区成员




select
(case when col='' then year(getdate()) else col end )as col
From tb
/*
2004
2005
2006
2007
*/
select case when a='' then DATEPART (yy,getdate()) else a end
from (select '2004' a union select '2005' union select '2006' union select'2007' union select'' )b
/*
2009
2004
2005
2006
2007
*/
update tb set A=year(getdate())
where A='‘’'
create table #t (a varchar(20))
insert into #t select '2004' a union select '2005' union select '2006' union select'2007' union select''
/*
2004
2005
2006
2007
*/
select case when a='' then DATEPART (yy,getdate()) else a end from #t
/*
2009
2004
2005
2006
2007
*/
update tb set A=case when A='' then year(getdate()) else A end
update T
set col=case when col='' then CAST(RTRIM(YEAR(GETDATE())) +'0101' AS DATETIME ) else col end
SELECT CASE WHEN A ='' THEN CAST(RTRIM(YEAR(GETDATE())) +'0101' AS DATETIME ) END
update tablename set A=rtrim(datepart(yy,getdate())) where A=''