Default parameter in SQL function
Posted on 2008-06-17
I have been tasked to create a report that compares the sum of values from the previous year, the current month and ytd in three columns. In my first stab at it, I created a ytd function and a monthly function. I'd like to refine this by creating one function that uses an either default parameter that I either won't use or an optional parameter. Something like
CREATE FUNCTION dbo.TESTFUNCTION(@PERIOD INT, @YEAR INT, @MONTH INT) <<< I would like @MONTH to be optional. If @PERIOD = 1 then I'm going for a yearly total and I don't need the month.