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
 Transact-SQL (2000)
 Working with sql statement written in string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-07-11 : 11:18:49
Ishita writes "set @sqlString2 = 'update '+@tableName +' set ' + @GRP_nm + ' = '+@stringCat +' where ' + @Racf_id + ' = ''' + @currGrp_nm + ''''
--exec(@sqlString2)

I am trying to execute above string and it is not working.
everyfield is varchar. please help"

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-11 : 11:23:44
Try printing the string rather than executing it.
maybe

set @sqlString2 = 'update '+@tableName +' set ' + @GRP_nm + ' = '''+@stringCat +''' where ' + @Racf_id + ' = ''' + @currGrp_nm + ''''

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-07-11 : 11:24:08
If you run this instead, does the sql string look the way you want? If you run it, do you get an error? If so, what is it?

set @sqlString2 = 'update '+@tableName +' set ' + @GRP_nm + ' = '+@stringCat +' where ' + @Racf_id + ' = ''' + @currGrp_nm + ''''
print @sqlString2


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-11 : 11:24:19
[code]set @sqlString2 = 'update '+@tableName +' set ' + @GRP_nm + ' = '''+@stringCat +''' where ' + @Racf_id + ' = ''' + @currGrp_nm + ''''[/code]


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-11 : 11:27:11
Double



KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-12 : 02:51:44
http://www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -