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
 General SQL Server Forums
 New to SQL Server Programming
 question about procedure

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 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)

17689 Posts

Posted - 2012-09-25 : 21:39:06
[code]where t.id = @p_required
or @p_required is null[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

olybobo
Starting Member

4 Posts

Posted - 2012-09-25 : 22:07:33
quote:
Originally posted by khtan

where t.id = @p_required
or @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...
Go to Top of Page

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]

Go to Top of Page

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?
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

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

or
exec test



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -