关于日期值的设置
在存储过程中:
有一个参数@pDate as datetime
Declare @pYear as int
Declare @pBDate as datetime
set @pYear=year(@pDate)
set @pBDate=***在这里我希望把这个时间设置为@pYear年1月1日,该怎么写
我这样写不行:set @pBDate=CONVERT(DATETIME, @pYear& '-1-1 ', 102)
------解决方案--------------------declare @pDate datetime
Declare @pYear varchar(10)
Declare @pBDate datetime
set @pYear=DATENAME(year,@pDate)
set @pBDate=@pYear+ '-01-01 '
--or:
declare @pDate datetime
Declare @pYear int
Declare @pBDate datetime
set @pYear=year(@pDate)
set @pBDate=cast(@pYear as varchar)+ '-01-01 '
------解决方案--------------------set @pBDate=CONVERT(DATETIME, @pYear& '-1-1 ', 102)
==>
set @pBDate = convert(datetime,cast(@pYear as char(4)) + '-1-1 ',102)