如何将我的字段值放在引号内(SQL)

时间:2014-03-10 12:25:06

标签: sql

下面的代码在包含逗号的字段中的任何值周围加上引号。

SELECT case when CHARINDEX(',',myField) > 0 
THEN '"'+ myField +'"' else myField END AS myField 
FROM myTable

问题是我想选择myField作为地址,但因为我已经有了END AS,所以我不知道如何去做。希望我的问题很明确。请帮忙。

1 个答案:

答案 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