I want to create a function similar to DATEDIFF in MS SQL Server 2008 R2. The first parameter in DATEDIFF is a datepart. Can I use datepart as a parameter in my function? If not, how do I create a parameter similar to datepart? I don't want to make the parameter text.
For example, I would like to have a function like this: MYFUNC(datepart, timestart, timeend)
So when I call the function, it would look like this: MYFUNC(Hour, N'08:00:00', N'12:00:00')
I'm currently using a nvarchar for the datepart param so my function looks like this: MYFUNC(N'Hour', N'08:00:00', N'12:00:00')
HOUR
as a parameter - you need to pass a value that conforms to one of the data types since your parameter must be declared using a data type. Can you explain what you want to do differently fromDATEDIFF
?datediff
.