日期:2014-05-18  浏览次数:20768 次

关于adteadd的一条写法
dateadd(mm,-1,@jieshou)
这样写可以吗?

------解决方案--------------------
return (datepart(yy,@jieshou)+ '- '+dateadd(mm,-1,@jieshou)+ '- '+ '29 '
这样写可以吗?

-------
改為
return ( Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) - 1 As Varchar) + '- '+ '29 '
------解决方案--------------------
--直接在你函數上修改

create function f_getlasttenday1(@shuru char(8))

returns datetime
begin
declare --@lasttedday smalldatetime,
@jieshou datetime
set @jieshou=dbo.chackdate(@shuru )
if datepart(dd,@jieshou) <11
if datepart(mm,@jieshou)=1
return Cast(year(@jieshou) -1 As Varchar)+ '- '+ '12 '+ '- '+ '31 '
else
begin
if(datepart(mm,@jieshou) in ( '2 ', '4 ', '6 ', '8 ', '9 ', '11 ', '1 '))
return Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) As Varchar)+ '- '+ '31 '
else
begin
if (datepart(mm,@jieshou)=3)
begin
if ((datepart(yy,@jieshou)%100=0) or datepart(yy,@jieshou)%400=0)
return Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) - 1 As Varchar) + '- '+ '29 '
else
return Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) - 1 As Varchar) + '- '+ '28 '
end
else

return Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) - 1 As Varchar) + '- '+ '30 '
end
end
else
begin
if datepart(dd,@jieshou) <21
return Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) As Varchar) + '- '+ '10 '
else
return Cast(year(@jieshou) As Varchar)+ '- '+ Cast(month(@jieshou) As Varchar) + '- '+ '20 '
end
return '1 '
end
GO
Select dbo.f_getlasttenday1( '20070130 ')
Select dbo.f_getlasttenday1( '20070330 ')
Select dbo.f_getlasttenday1( '20070310 ')
GO
Drop Function f_getlasttenday1