问题描述
我需要从 SQL 导出数据并导入到 SAS.地址字段的字符串中间有,".我尝试使用 CSV 和制表符分隔,但每次 SAS 都会因,"而拆分地址字段.
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...
推荐答案
如果你想用单引号将字符串括起来,你必须像这样对它们进行转义:
If you want to surround the string with single-quotes you have to escape them like this:
update #temp2 set STREETADDRESS_e = ('''' + STREETADDRESS_e + '''')
或
update #temp2 set STREETADDRESS_e = QUOTENAME(STREETADDRESS_e,'''')
或者如果你想要双引号
update #temp2 set STREETADDRESS_e = QUOTENAME(STREETADDRESS_e,'"')
这篇关于在变量周围添加引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!