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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 can anybody help me to solve this issue

Author  Topic 

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-07-18 : 08:34:46
hi all,

i have a dynamic sql statements, i am trying to execute with
exec(@l_sql) but it is not executing how to execute the following sql statement using sp_executesql

declare @str varchar(30),@p_wherecondition varchar(2000),@totalquery nvarchar(2000),@paramdef nvarchar(200)
set @str='''CH'',''EV'''
set @p_wherecondition='hipl_id=''hofpr01'''

SELECT @L_TOTALQUERY='SELECT * FROM #ATTRTABLE WHERE FLAGCODE NOT IN('+@STR+') AND HIPL_ID IN(SELECT HIPL_ID FROM VIW_CATALOGUE WHERE ' +@P_WHERECONDITION + ')'
set @paramdef='@str varchar(30),@p_wherecondition varchar(2000)'

execute sp_executesql @l_totalquery,@paramdef

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-18 : 09:29:55
Substitute execute with PRINT for a while, and you will see where the error is.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-21 : 09:31:18
what error do you got?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-21 : 11:37:36
try like this:-
declare @str varchar(30),@p_wherecondition varchar(2000),@totalquery nvarchar(2000),@paramdef nvarchar(200)
set @str='''CH'',''EV'''
set @p_wherecondition='hipl_id=''hofpr01'''

SELECT @L_TOTALQUERY='SELECT * FROM #ATTRTABLE WHERE FLAGCODE NOT IN(@STR) AND HIPL_ID IN(SELECT HIPL_ID FROM VIW_CATALOGUE WHERE @P_WHERECONDITION)'
set @paramdef='@str varchar(30),@p_wherecondition varchar(2000)'

execute sp_executesql @l_totalquery,@paramdef
Go to Top of Page
   

- Advertisement -