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
 error if else
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

212 Posts

Posted - 04/24/2013 :  01:53:53  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote

In the below part of code i get error in else if i have exec (@sql_query).
if i remove exec (@sql_query), i am not getting error. please help

If @category_id in (3,4)
set @sql_query = 'SELECT category.category_id, '+LTRIM(RTRIM( @category_Desc ))+'_name as [Category Detail] FROM category '
exec (@sql_query)
else
set @sql_query = 'SELECT NULL as category_id, NULL as [Category Detail] '
select (@sql_query )


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 04/24/2013 :  02:14:19  Show Profile  Reply with Quote
If @category_id in (3,4)
BEGIN
	set @sql_query = 'SELECT category.category_id, '+LTRIM(RTRIM( @category_Desc ))+'_name as [Category Detail] FROM category '
	exec (@sql_query)
END
else
BEGIN
	set @sql_query = 'SELECT NULL as category_id, NULL as [Category Detail] '
	select (@sql_query ) 
END


--
Chandu
Go to Top of Page

shanmugaraj
Posting Yak Master

212 Posts

Posted - 04/24/2013 :  02:44:20  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
Thanks Chandu

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

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 04/24/2013 :  02:53:17  Show Profile  Reply with Quote
quote:
Originally posted by shanmugaraj

Thanks Chandu

Welcome

NOTE: Make sure to use BEGIN..END blocks in the case of more than one statements

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