I'm guessing this is not possible since the engine doesn't like it, but is there a way (barring dynamic SQL) to pass in a DATEPART
as a parameter to a procedure?
Why can't you just pass in the Date that is created from the Datepart?
DECLARE @datepart DATETIME
SET @datepart = DATEPART(yyyy, GetDate())
exec spName @datepart
Best solution is to always add months (or even days if you need it on that level) and to play with integer values. Something like this
DECLARE @AddMonths INT = 12
SELECT
Sales_DateTime, DATEADD(DAY, -1, DATEADD(MONTH, @AddMonths, DATEADD(DAY, 1, Sales_DateTime )))
FROM tSales
and I think it's clear how to add one month only :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With