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.
Author |
Topic |
derisen
Starting Member
4 Posts |
Posted - 2012-07-27 : 06:36:21
|
Requirement:We need to insert the below string to a column via sqlcmd.'Ex:[$AGM$'++'(Person.Name=''xyz'')]' Problem:If we run the same through ssms its working. But if executing through sqlcmd then its failing, since '$(' is a prefix of a variable in sql cmd mode and it expects a variable.Help required on:Is there any escape characters to allow '$(' within a sql string?Can any one suggest a solution for executing the string -print 'Ex:[$AGM$'++'(Person.Name=''xyz'')]' in ssms query analyser and also via sqlcmd?Note: Person.Name is not a variable. |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2012-07-27 : 07:14:05
|
just use more single quotes as you would in a dynamic SQL command.so'Ex:[$AGM$'++'(Person.Name=''xyz'')]' would become something like (probably not totally correct, but you get the idea):''Ex:[$AGM$''++''(Person.Name=''''xyz'''')]'' The easiest way is if you put your insert into a variable in SSMS and try to run it with sp_executesql, if it works there, it will work from sqlcmd. |
 |
|
|
|
|