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)
 Dynamic Query Help

Author  Topic 

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2005-11-17 : 16:41:25
I am trying to create a dynamic query, guys, what am I doing wrong. I tried to run the query below in query analyser and I can't

declare @SQL varchar(2000)
declare @GroupNumber int
declare @inputSQL varchar(200)

set @inputSQL = 'CurrentBalance < 5464563456 OR Borrower1 < 600 '
set @GroupNumber = 1

select @SQL = ' update TempTable set GroupId = ' + @GroupNumber + ' where ' + @inputSQL

Execute (@sql)

Error Recieved from App.
==========================

Server: Msg 245, Level 16, State 1, Line 8
Syntax error converting the varchar value ' update TempTable set GroupId = ' to a column of data type int.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-11-17 : 18:23:06
You just need to change that line to convert the int to varchar.


select @SQL = 
' update TempTable set GroupId = ' +
convert(varchar(20),@GroupNumber) +
' where ' + @inputSQL





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -