I have a stored procedure and table consists of integer for date for year, month, day.
BEGIN
SET NOCOUNT ON;
SELECT
[Address],
FROM [dbo].[Stats]
WHERE DATEADD(year, [year]-1900, DATEADD(month, [month]-1, DATEADD(day, [day]-1, DATEADD(hour, [hour]-1, DATEADD(minute, [minute]-1, 0))))) >= @datetime
END
If I pass datetime into stored procedure how can I do where statement. How can I simplifiy procedure below?
Also I tried this
DATEADD(year, [year]-1900, DATEADD(month, [month]-1, DATEADD(day, [day]-1, DATEADD(hour, [hour]-1, DATEADD(minute, [minute]-1, 0))))) as [DateTime]
FROM [dbo].[Stats]
AND [DateTime] >= @datetime
And it says [DateTime] doesn't exist, how can I assign AS new field from calculation in stored procedure? It works normal in query.