|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
varchar questionHi there
How do I get a string like this into a variable? SELECT * FROM dbTemp WHERE field='TEST' It's the '' that gives me problem. /Nettan SET @var = 'SELECT * FROM dbTemp WHERE field=''TEST'''
Double up each single quote in the string. -- Show quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ Blog: http://solidqualitylearning.com/blogs/tibor/ "Nettan" <Net***@discussions.microsoft.com> wrote in message news:D1B2C610-9A93-4685-854C-E63EB2C60CA6@microsoft.com... > Hi there > > How do I get a string like this into a variable? > SELECT * FROM dbTemp WHERE field='TEST' > > It's the '' that gives me problem. > > /Nettan You can specify 2 single quotes in a literal string when one is desired in
the result. For example: SET @MySqlStatement = 'SELECT * FROM dbTemp WHERE field=''TEST''' Before resorting to dynamic SQL, please review Erland's article on dynamic SQL considerations: http://www.sommarskog.se/dynamic_sql.html. -- Show quoteHope this helps. Dan Guzman SQL Server MVP "Nettan" <Net***@discussions.microsoft.com> wrote in message news:D1B2C610-9A93-4685-854C-E63EB2C60CA6@microsoft.com... > Hi there > > How do I get a string like this into a variable? > SELECT * FROM dbTemp WHERE field='TEST' > > It's the '' that gives me problem. > > /Nettan double the single quoptes to escape:
--example DECLARE @MyVariable varchar(2000) SET @MyVariable = 'SELECT * FROM dbTemp WHERE field=''TEST''' -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA *************************** Think Outside the Box! *************************** "Nettan" wrote: > Hi there > > How do I get a string like this into a variable? > SELECT * FROM dbTemp WHERE field='TEST' > > It's the '' that gives me problem. > > /Nettan |
|||||||||||||||||||||||