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.
Author |
Topic |
olybobo
Starting Member
4 Posts |
Posted - 2012-09-25 : 21:32:41
|
dear all;I have a quick question. I have the following procedure belowcreate PROCEDURE test( @p_required INT )asselect * from tbl_test twhere t.id = @p_requiredwhat i want is if @p_required is not null or empty, then make use of it and if @p_required is null or empty then just grab everything from the tbl_test...I need help with the syntax please |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-25 : 21:39:06
|
[code]where t.id = @p_requiredor @p_required is null[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
olybobo
Starting Member
4 Posts |
Posted - 2012-09-25 : 22:07:33
|
quote: Originally posted by khtan
where t.id = @p_requiredor @p_required is null KH[spoiler]Time is always against us[/spoiler]
that wouldn't work man, do you understand my requirement...it is basically grab everything from the table if p_required is null or empty... |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-25 : 22:26:30
|
NULL is not EMPTY. EMPTY is not NULL.what do you pass in for @p_required if you want the stored procedure to return everything ? KH[spoiler]Time is always against us[/spoiler] |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-09-25 : 22:27:31
|
quote: that wouldn't work man, do you understand my requirement...it is basically grab everything from the table if p_required is null or empty...
Maybe you should test it first before criticizing? |
|
|
olybobo
Starting Member
4 Posts |
Posted - 2012-09-25 : 22:53:19
|
quote: Originally posted by khtan NULL is not EMPTY. EMPTY is not NULL.what do you pass in for @p_required if you want the stored procedure to return everything ? KH[spoiler]Time is always against us[/spoiler]
i will pass in a null |
|
|
olybobo
Starting Member
4 Posts |
Posted - 2012-09-25 : 22:54:18
|
quote: Originally posted by robvolk
quote: that wouldn't work man, do you understand my requirement...it is basically grab everything from the table if p_required is null or empty...
Maybe you should test it first before criticizing?
i tried it man and it didn't work |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-25 : 23:25:20
|
is this how you execute the stored procedure ?exec test @p_required = NULL orexec test KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|