Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@parameter = NULL in stored proc

Status
Not open for further replies.

kimr

Programmer
Jun 12, 2001
16
US
As part of the upgrade to SQL Server 7.0 we are changing all "= NULL" to "IS NULL" in stored procs. I have one that declares a parameter as "@parm = NULL". SQL Server 6.5 nor 7.0 will accept "@parm IS NULL" when declaring. Any advise?
 
Leave it as it is!
If its a parameter declaration then the = is correct.
If it is a comparision to Null then use the IS command

Like this:

CREATE PROCEDURE sp_GetInfo (@state char(2) = NULL)
AS
select * from authors
where state = coalesce(@state,state)
 
Hi kimr,
In SQL 6.5 or SQL 7.0, while creating the input/ouput parameters you have to use
@param datatype = null
only.
Ofcourse in rest of the procedure where you are checking the paramete's value (e.g. IF @param = null) you should replace it with IF @param is null.

Hope this will resolve your cofusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top