| Author |
Topic  |
|
|
olybobo
Starting Member
4 Posts |
Posted - 09/25/2012 : 21:32:41
|
dear all;
I have a quick question. I have the following procedure below
create PROCEDURE test ( @p_required INT ) as
select * from tbl_test t where t.id = @p_required
what 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)
Singapore
16769 Posts |
Posted - 09/25/2012 : 21:39:06
|
where t.id = @p_required
or @p_required is null
KH Time is always against us
|
 |
|
|
olybobo
Starting Member
4 Posts |
Posted - 09/25/2012 : 22:07:33
|
quote: Originally posted by khtan
where t.id = @p_required
or @p_required is null
KH Time is always against us
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)
Singapore
16769 Posts |
Posted - 09/25/2012 : 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 Time is always against us
|
 |
|
|
robvolk
Most Valuable Yak
USA
15567 Posts |
Posted - 09/25/2012 : 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 - 09/25/2012 : 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 Time is always against us
i will pass in a null |
 |
|
|
olybobo
Starting Member
4 Posts |
Posted - 09/25/2012 : 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)
Singapore
16769 Posts |
Posted - 09/25/2012 : 23:25:20
|
is this how you execute the stored procedure ?
exec test @p_required = NULL or
exec test
KH Time is always against us
|
 |
|
| |
Topic  |
|