如何在sql中用单引号和逗号连接列值?
select tpaa_id from dbo.Sheet
where tpaa_id is not null
Run Code Online (Sandbox Code Playgroud)
目前查询返回,值为..
ABC123
ABC456
Run Code Online (Sandbox Code Playgroud)
我们有大约 1000 条记录。
我希望返回
'ABC123',
'ABC456',
Run Code Online (Sandbox Code Playgroud)
您可以使用变量进行连接:
declare @result nvarchar(max)
select @result = isnull(@result + ', ', '') + '''' + tpaa_id + ''''
from dbo.Sheet
where tpaa_id is not null
select @result
Run Code Online (Sandbox Code Playgroud)
小智 5
使用这种结构
SELECT CONCAT(CHAR(39), MyString ,CHAR(39)) FROM Table
return '<MyString>'
Run Code Online (Sandbox Code Playgroud)