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 |
|
VincentFrandsen
Starting Member
39 Posts |
Posted - 2007-03-22 : 05:36:10
|
| i have the following code @ value is my problem... i have to place it in single quotes but how do i get aroun the problem i have when my data has single quotes in its values...i.e. @value = "O'Brian" DECLARE @SQL as Varchar(max)set @sql = 'UPDATE schBank.TblLeads' + convert(varchar(10), @CampaignId) + ' SET [' + convert(varchar(10), @FieldId) + '] = ''' + @Value + ''' WHERE [TransactionId] = ' + convert(varchar(10), @TransactionId)PRINT @SQLEXECUTE ('' + @sql + '')Vincent Fradnsen |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-22 : 05:44:03
|
quote: Originally posted by VincentFrandsen i have the following code @ value is my problem... i have to place it in single quotes but how do i get aroun the problem i have when my data has single quotes in its values...i.e. @value = "O'Brian" DECLARE @SQL as Varchar(max)set @sql = 'UPDATE schBank.TblLeads' + convert(varchar(10), @CampaignId) + ' SET [' + convert(varchar(10), @FieldId) + '] = ''' + Replace(@Value, '''', '''''') + ''' WHERE [TransactionId] = ' + convert(varchar(10), @TransactionId)PRINT @SQLEXECUTE ('' + @sql + '')Vincent Fradnsen
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-22 : 05:48:16
|
| Or use QUOTENAME function.Peter LarssonHelsingborg, Sweden |
 |
|
|
VincentFrandsen
Starting Member
39 Posts |
Posted - 2007-03-22 : 05:50:22
|
| Thanks Harsh that works like a BOMB...Vincent Fradnsen |
 |
|
|
VincentFrandsen
Starting Member
39 Posts |
Posted - 2007-03-22 : 05:53:54
|
| Hi Peso Looked it up on BOL but i dont really understand how it works... please could you give me a better example...Vincent Fradnsen |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 06:02:16
|
try thisselect QUOTENAME('test') KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-22 : 06:17:10
|
| If you want it as [].If you want single quote ' use QUOTENAME( value , CHAR(39))Peter LarssonHelsingborg, Sweden |
 |
|
|
VincentFrandsen
Starting Member
39 Posts |
Posted - 2007-03-22 : 09:00:09
|
| thanksVincent Fradnsen |
 |
|
|
|
|
|
|
|