これは機能する私のクエリです:
Select AsOfDate, Family, Type, DocID, Title, Date1, Date2, Date3, Stat1, Stat2, Stat3
FROM DocumentationData
WHERE Type = @Type
AND Family = @Family
AND AsOfDate = (SELECT Max(AsOfDate)
FROM DocumentationData
WHERE AsOfDate <= @CurrentDate )
条件を追加したい。@ActiveOnly が true の場合、Usage = 'Active" という追加の制約が必要です。
これは私が試みていることですが、エラーが発生します:
Select AsOfDate, Family, Type, DocID, Title, Date1, Date2, Date3, Stat1, Stat2, Stat3
FROM DocumentationData
WHERE Type = @Type
AND Family = @Family
AND AsOfDate = (IF (@ActiveOnly = 'TRUE')
BEGIN
SELECT Max(AsOfDate)
FROM DocumentationData
WHERE AsOfDate <= @CurrentDate
AND Usage = 'Active'
END
ELSE
BEGIN
SELECT Max(AsOfDate)
FROM DocumentationData
WHERE AsOfDate <= @CurrentDate
END
)