日付 (YYYMMDD) のユーザー入力を持つストアド プロシージャがあります。
クエリの最後の部分を作成するには、12 か月前の日付に入力された日付を取得する必要があります。
datetime または dateadd 関数としてキャストするなど、いくつかの異なる方法を試しましたが、まだうまくいきません: 以下は私のコードの抜粋です:
@DateSelected datetime=null,
@year int=null,
@week int=null,
@DayOfWeek int=null,
@DateSelectedLastYear datetime=null
--@Day int=null
as
begin
--if date parms are null get current week and year
if (@DateSelected is null)
begin
select @Year=year_number,@Week=week_number,@DayOfWeek=day_of_week from infrastructure..calendar
where calendar_date=DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-1))
end
else
begin
select @Year=year_number,@Week=week_number,@DayOfWeek=day_of_week from infrastructure..calendar
where calendar_date=@DateSelected
end
begin
Select
@DateSelectedLastYear = DATEADD(YYYY,-1,@DateSelected)
end