Tuesday, November 08, 2005

SQL Server Parameter Default Value Problem

RANT: Ok, so I understand that sometimes there are reasons why some things are allowed and others are not. However, I haven't been able to justify this one.


If I want to default a stored procedure parameter to today's date if left empty, I can't do it. Reason being only a constant or Null can be a default value of a parameter. Ok, fine. I'll set the default to null then evaluate if it's null in the SP and set to GetDate(). It's a workaround and another couple lines of code that don't need to be there.


My question is this though: Why can I set a column in a table to a default value of GetDate() but not in a stored procedure? Even better, if you try to create a stored procedure with this assignment by default, it gives you some strange error about ")" or whatever line precedes the assignment and doesn't explain that a constant wasn't found.