下面的代码在包含逗号的字段中的任何值周围加上引号。
SELECT case when CHARINDEX(',',myField) > 0
THEN '"'+ myField +'"' else myField END AS myField
FROM myTable
问题是我想选择myField作为地址,但因为我已经有了END AS,所以我不知道如何去做。希望我的问题很明确。请帮忙。
答案 0 :(得分:0)
除非我完全误解了您,否则您只需在查询中添加myField as address
即可:
SELECT
case when CHARINDEX(',',myField) > 0
THEN '"'+ myField +'"' else myField END AS myField,
myField as address
FROM myTable
<强>更新强>
只获取一个名为address的列:
SELECT
case when CHARINDEX(',',myField) > 0
THEN '"'+ myField +'"' else myField END AS address
FROM myTable