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
 IF else in SP with null param
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

214 Posts

Posted - 03/26/2013 :  06:25:02  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
Kindly help me with the if else part on below SP

CREATE PROCEDURE [dbo].[usp_get_data]
( @poi [nvarchar](10) = NULL)
AS
BEGIN
IF @poi = NULL Then
SELECT poi_category from poi_master
else
SELECT poi_category from poi_master where poi_code =@poi
end if
END

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 03/26/2013 :  06:36:39  Show Profile  Reply with Quote
BEGIN
IF @poi IS NULL Then
SELECT poi_category from poi_master
else
SELECT poi_category from poi_master where poi_code =@poi
end if
END

remove the striked keywords and make sure IS operator instead of = operator
Go to Top of Page

shanmugaraj
Posting Yak Master

214 Posts

Posted - 03/26/2013 :  07:12:20  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
can i write as concordinating query like where in i can save space and time

BEGIN
strsql = "SELECT poi_category from poi_master"
IF @poi IS NOT NULL Then
strsql = strsql + "where poi_code =@poi"
end if

exec strsql
END


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 03/26/2013 :  07:29:08  Show Profile  Reply with Quote
SELECT poi_Category
FROM poi_master
WHERE poi_code = @poi OR @poi IS NULL
Go to Top of Page

shanmugaraj
Posting Yak Master

214 Posts

Posted - 03/26/2013 :  08:15:52  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
Thanks bandi

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 03/26/2013 :  08:21:01  Show Profile  Reply with Quote
quote:
Originally posted by shanmugaraj

Thanks bandi
THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

Welcome

--
Chandu
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.03 seconds. Powered By: Snitz Forums 2000