Sp Null

farshad

Well-known member
Joined
May 1, 2003
Messages
109
Location
London
In vb.net i am running a stored procedure in sql server 2000
the SP is something like:

@Curve int
.
.
.
@Qualifier varchar(3) = NULL
AS
select * from table1 where
curve=@Curve
.
.
.
AND Qualifier = @Qualifier

Basically the question is that when i run the query like select * from table1 where Qualifier IS NULL
it works and returns data but in SP when no @Qualifier is passed then it becomes select * from table1 where Qualifier = NULL

when it is = null it does not return data
and thoughts?
thanks
 
<anything> = NULL will always return NULL.

Probably the easiest way is alter the SP so that you check for NULL and act accordingly

i.e.
Code:
Create proc 
.
.
.
.
AS

if @Qualifier is NULL
Begin
    --Code to handle NULL here
    select * from table1 where
    curve=@Curve
    .
    .   
    .
AND Qualifier IS NULL
End
Else
Begin
    --Non Null here
select * from table1 where
curve=@Curve
    .
    .
    .
    AND Qualifier = @Qualifier
End
 
Back
Top