SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 question about procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

olybobo
Starting Member

4 Posts

Posted - 09/25/2012 :  21:32:41  Show Profile  Reply with Quote
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
17681 Posts

Posted - 09/25/2012 :  21:39:06  Show Profile  Reply with Quote
where t.id = @p_required
or    @p_required is null



KH
Time is always against us

Go to Top of Page

olybobo
Starting Member

4 Posts

Posted - 09/25/2012 :  22:07:33  Show Profile  Reply with Quote
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...
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17681 Posts

Posted - 09/25/2012 :  22:26:30  Show Profile  Reply with Quote
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

Go to Top of Page

robvolk
Most Valuable Yak

USA
15683 Posts

Posted - 09/25/2012 :  22:27:31  Show Profile  Visit robvolk's Homepage  Reply with Quote
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 - 09/25/2012 :  22:53:19  Show Profile  Reply with Quote
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
Go to Top of Page

olybobo
Starting Member

4 Posts

Posted - 09/25/2012 :  22:54:18  Show Profile  Reply with Quote
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)

Singapore
17681 Posts

Posted - 09/25/2012 :  23:25:20  Show Profile  Reply with Quote
is this how you execute the stored procedure ?
exec test @p_required = NULL

or
exec test



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000