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
 error if else

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-24 : 01:53:53

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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-24 : 02:14:19
[code]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[/code]

--
Chandu
Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-24 : 02:44:20
Thanks Chandu

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

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-24 : 02:53:17
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
   

- Advertisement -