Add quotes around variable(在变量周围添加引号)
问题描述
我需要从 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,'"')
这篇关于在变量周围添加引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在变量周围添加引号


基础教程推荐
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01