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
 IF else in SP with null param

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-03-26 : 06:25:02
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-26 : 06:36:39
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

219 Posts

Posted - 2013-03-26 : 07:12:20
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
Master Smack Fu Yak Hacker

2242 Posts

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

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-03-26 : 08:15:52
Thanks bandi

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

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-26 : 08:21:01
quote:
Originally posted by shanmugaraj

Thanks bandi
THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -