我必须从SQL服务器表中选择以下格式的数据。
Ex table名称:样本
表示例有一列名为Text,该列的数据类型为nvarchar(20)。
所以在该专栏中我有一个数据:
Text
-------
'aaa'
'bbbb'
'c'
ddd'
'ee
所以通过使用上面的列数据我想要输出如下:
Text
--------
aaa
bbbb
c
ddd
ee
所以请提供我如何通过SQL服务器查询获得此信息。
答案 0 :(得分:0)
如果您要删除Single quotes(')
,则使用Replace
函数
Update tablename set Text = replace(Text,'''','')
或者您只想选择结果。
select replace(Text,'''','')
from yourtable
答案 1 :(得分:0)
使用SQL REPLACE()
试试这样:
Select REPLACE([text],'''','') from Table_Name
答案 2 :(得分:0)
一种方式:
;with sample ([text]) as (
select '''abc''' union
select '''abc' union
select 'abc''' union
select 'a''b''c' union
select '''a''b''c'''
)
select
text,
substring(text,
patindex('''%', text) + 1,
len(text) - case when right(text, 1) = '''' then patindex('''%', text) + 1 else 0 end
)
from sample
text (No column name)
'a'b'c' a'b'c
'abc abc
'abc' abc
a'b'c a'b'c
abc' abc