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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 eradicate null values from stored procedure input

Author  Topic 

lazydev
Starting Member

16 Posts

Posted - 2008-04-07 : 14:06:18
my stored procedure is

create procedure t1 (@a int,@b int,@c int,@d int,@e int,@f int)
as
begin
select no,name,department from emp where a = @a and b =@b orc =@c or
d = @d or e = @e or f = @f
end

my problem is while executing i may get null values as input to the stored procedure .
how to validate them ? any ideas .
are there any arrays.
if c and d are null then my condition would be
where a = @a and b =@b or e = @e or f = @f
how many loops shall i have to write.






jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-04-07 : 14:17:40
where IsNull(@a, a) = a
and IsNull(@b, b) = b
and etc

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

lazydev
Starting Member

16 Posts

Posted - 2008-04-07 : 14:22:30
quote:
Originally posted by jhocutt

where IsNull(@a, a) = a
and IsNull(@b, b) = b
and etc

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking




if the value of a or b or c is null it should not be in select criteria.rest all should be there
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-04-07 : 14:26:04
That is basically what that will accomplish. If it is null it will compare the column with its self.


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-04-07 : 14:51:54
where (@a is null or a=@a) and (@b is null or @b=b) and ... etc ....

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -