Tuesday, October 27, 2009

How to insert ' character in sql server

Heard Many done Many times but couldn't find a better google link
so posting it here for my own use or someone elses may be :)

Had a requirement to insert special characters ' in nvarchar
Now the data to be inserted is
Integrated Security=SSPI;Pooling='true';Persist Security Info=False;Initial Catalog=xyz;Data Source=LocalHost;Min Pool Size=5

we have a table whose value coulmn(Value column is of nvarchar(1024) type) needs to be inserted with this data(note the data to be inserted carries a 'true' value also)
so the trick is here-

update mytable set
value= 'Integrated Security=SSPI;Pooling=''true'';Persist Security Info=False;Initial Catalog=sleepme;Data Source=LocalHost;Min Pool Size=5' where idname='DataLocation'

Relief....

No comments:

Post a Comment