Assume I have a table looks like this:
Scores {
Id uniqueidentifier,
ScoredAt datetime,
Value int
}
Basically I want to create a stored procedure that works similar to this DATEDIFF(DAY, @day, GETDATE()) which can use DAY/WEEK... as parameter. This is what i did:
CREATE PROCEDURE GetHighScores
@scope int --- <<== THIS GUY HERE
AS
BEGIN
SELECT *
FROM Honor.Scores
WHERE DATEDIFF(@scope, Honor.Scores.ScoredAt, GETDATE()) = 0
END
GO
What do I have to put into GetHighScores parameter so that I can do this:
EXEC GetHighScores(MONTH)
As far as I know, MONTH/WEEK/DAY.. those are not actually a value but more of a tricky macro. But that guy DATEDIFF can use it, why couldn't I?
Anyone have any idea to get this done?
MONTH
into@scope
, which is anINT
? (4) What version of SQL Server please?