How to set deafult null value in to a date field in the table,if the parameter containing the date value is null?
A:
Do you mean how do you set a specific default value in a stored procedure when the date parameter passed in is NULL?
Mark your date parameter like this:
@DOB DATETIME = '01/01/1900'
And the @DOB parameter would then insert '01/01/1900' if @DOB is passed as NULL.
Brian Scott
2009-10-19 11:01:36
if the date parameter is null then the dafault value will be '01/01/1900'.I want this to be NULL
Adarsh
2009-10-19 11:11:03
A:
Try:
coalesce(param, getdate())
in your stored procedure or define a default value on your column
ALTER TABLE dbo.Mitarbeiter ADD CONSTRAINT
DF_Mitarbeiter_Geburtstag DEFAULT getdate() FOR Geburtstag
Arthur
2009-10-19 11:02:28
A:
I am not expert on sql server 2000.
i got one link hope this will help you :)
anishmarokey
2009-10-19 11:23:17
+1
A:
Make sure you are really passing in NULL, I think you are passing in an empty string. If you pass in empty string, you get the 1900-01-01 00:00:00.000
value that you refer to. Null will be null and not change to a date.
try this test code:
declare @x datetime
select 'is null', @x
set @x=''
select 'is empty string', @x
OUTPUT:
------- -----------------------
is null NULL
(1 row(s) affected)
--------------- -----------------------
is empty string 1900-01-01 00:00:00.000
(1 row(s) affected)
KM
2009-10-19 15:26:06