Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add quotes around variable

I need to export data from SQL and import into SAS. The address field has ',' in the middle of the string. I tried using CSV and tab delimited, but each time SAS breaks up the address field due to the ','.

I tried replacing the comma with a space using code from another question, but it did not work:

 update #temp2
 set STREETADDRESS_e = REPLACE(STREETADDRESS_e ,","," ")

I thought if I put the address string in quotes, this would solve the problem, but my code is not working:

 update #temp2
 set STREETADDRESS_e = ("'" + STREETADDRESS_e + "'")

This seems like it must be a very common problem but I have not found any working solutions...

like image 941
vfiola Avatar asked Aug 18 '26 23:08

vfiola


1 Answers

If you want to surround the string with single-quotes you have to escape them like this:

update #temp2 set STREETADDRESS_e = ('''' + STREETADDRESS_e + '''')

or

update #temp2 set STREETADDRESS_e = QUOTENAME(STREETADDRESS_e,'''')

or if you want double-quotes

update #temp2 set STREETADDRESS_e = QUOTENAME(STREETADDRESS_e,'"')
like image 74
jpw Avatar answered Aug 24 '26 09:08

jpw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!