CREATE PROC pr_GetLastJobDay
@Date DATETIME
AS
declare @lastday datetime
--得到這個月的最後一天
set @lastday=dateadd(dd,-day(@date),dateadd(mm,1,@date))
while datename(weekday,@lastday) ='Saturday' or datename(weekday,@lastday) ='sunday'
begin
set @lastday=dateadd(dd,-1,@lastday)
end
select convert( nvarchar(10),@lastday ,120)
---------
GO
exec pr_GetLastJobDay '2007-04-20'