tags:

views:

34

answers:

2

I want to update a row which has some html tags inside. For instance

 src='/imagem.png'></ p></ body>

> UPDATE ISTANBUL_TABLE  SET TEXT = '<
> body>< p>< img src='/imagem.png '></
> p></ body>'  WHERE  1=1

you see after src=' means the query ends, but it does not end. how can i solve it without using " (double comma). any solution please?

best regards bk

+4  A: 

You need to escape the single-quotes, by typing them twice:

UPDATE ISTANBUL_TABLE SET TEXT = '<  body>< p>< img src=''/imagem.png ''>' WHERE 1=1

Also, your WHERE clause is nonsensical and can be dropped entirely

UPDATE ISTANBUL_TABLE SET TEXT = '<body><p><img src=''/imagem.png''>'
David Hedlund
double single-quotes is ok then?I mean where clause still has meaning after using twice single-quotes.
blgnklc
Not crazy about typing extra quotes -- it would be hard to spot an error. But I totally agree that the WHERE clause is not needed.
DOK
yeah you are right. but i will need the where clause for different cases of next operations
blgnklc
Yes, doubling single quotes is just escaping them so that they don't close the string. One of the (number of) reasons why it's neater to use parameterised SQL instead of adhoc generated like this as you don't need to worry about escaping like this
AdaTheDev
+1  A: 

Use parameterised SQL:

UPDATE ISTANBUL_TABLE SET TEXT = @HTML WHERE...

Then from your calling code, you just pass in the @HTML parameter and don't need to double up the single quotes.

AdaTheDev
the operation will be handled on sql management studio
blgnklc