I have a stored procedure in SQL Server 2008 that will insert a record into a table.
The sproc looks similar to this:
-- params
@f1 int,
@f2 datetime = null,
@f3 datetime,
@f4 bit = 0
BEGIN
INSERT INTO dbo.table
(fields......)
VALUES
(@params.....)
RETURN @@IDENTITY
END
Prior to running the INSERT statement, I would like to trap the datetime value of the f2 param. If f2 is not a valid date I would like to set it to null.
I'm fuzzy on the syntax on how to do this. I thought the following would suffice, but not so:
--params
@f1..
@f2..
...
IF(ISDATE(@f2) < 1)
SET @f2= NULL
BEGIN
INSERT...
...
END
What is the syntax for trapping and resetting a param value prior to executing an INSERT?
By the way, the reason that led me to finding a solution to this problem is rooted in the fact that I'm passing a C# minimum date value of "1/1/0001" to SQLS which supports minimum date value of "1/1/1753".