Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Null parameter

Author  Topic 

kidaduo
Starting Member

45 Posts

Posted - 2008-05-05 : 10:48:19
I have a sql proc. I need to make a parameter optional. I've setup the parameter to use a dataset as its source, and I need NOT to allow the value to be null. I've NOT selected allow nulls check box, But, when the parameter is null (‘’), still data comes back in a table as empty or if it is date will default to 1/1/1900. How do I send a null value to the database through sql proc and raise an error without inserting a null value? I’m hoping to avoid creating a special query just for that purpose.

Thanks.


Josephine

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-05 : 10:52:37
CREATE PROC...
AS

SET NOCOUNT ON

IF @Param1 IS NULL
BEGIN
RAISERROR ( ' ... ', 16, 1)
RETURN
END



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-05 : 10:53:25
Or, if you just want to convert to NULL value to another value.

COALESCE(@Param1, GETDATE())



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

kidaduo
Starting Member

45 Posts

Posted - 2008-05-05 : 11:07:42
Thnak you Peso. I will try to use your suggestion. My server is down at a moment.

Thk

quote:
Originally posted by Peso

Or, if you just want to convert to NULL value to another value.

COALESCE(@Param1, GETDATE())



E 12°55'05.25"
N 56°04'39.16"




Josephine
Go to Top of Page
   

- Advertisement -