How to concatenate a column value with single quotes and a comma in sql?
如何将列值与单引号和sql中的逗号连接?
select tpaa_id from dbo.Sheet
where tpaa_id is not null
At present query returns, value as ..
目前查询返回,值为..
ABC123
ABC456
We have around 1000 records.
我们有大约1000条记录。
I expect to return as
我希望能够回归
'ABC123',
'ABC456',
3 个解决方案
#1
2
You can use variable for concatenation:
您可以使用变量进行连接:
declare @result nvarchar(max)
select @result = isnull(@result + ', ', '') + '''' + tpaa_id + ''''
from dbo.Sheet
where tpaa_id is not null
select @result
#2
0
You can simply concatenate the columns using the query
您可以使用查询简单地连接列
select ''''||tpaa_id||''''||',' from dbo.Sheet
where tpaa_id is not null;
#3
-1
hi
'UPDATE LinkedMySQLDB.TableToUpdate AS a SET a.MySQLField=''updated'' WHERE a.ID IN (LocalMSSQLDB.LocalTable.ID) ;'
This is a string constant but you need a value for LocalMSSQLDB.LocalTable.ID.
Declare @ldb int;
set @ldb = select LocalMSSQLDB.LocalTable.ID
'UPDATE LinkedMySQLDB.TableToUpdate AS a SET a.MySQLField='' + value + '' WHERE a.ID IN (' + @ldb + ') ;'
#1
2
You can use variable for concatenation:
您可以使用变量进行连接:
declare @result nvarchar(max)
select @result = isnull(@result + ', ', '') + '''' + tpaa_id + ''''
from dbo.Sheet
where tpaa_id is not null
select @result
#2
0
You can simply concatenate the columns using the query
您可以使用查询简单地连接列
select ''''||tpaa_id||''''||',' from dbo.Sheet
where tpaa_id is not null;
#3
-1
hi
'UPDATE LinkedMySQLDB.TableToUpdate AS a SET a.MySQLField=''updated'' WHERE a.ID IN (LocalMSSQLDB.LocalTable.ID) ;'
This is a string constant but you need a value for LocalMSSQLDB.LocalTable.ID.
Declare @ldb int;
set @ldb = select LocalMSSQLDB.LocalTable.ID
'UPDATE LinkedMySQLDB.TableToUpdate AS a SET a.MySQLField='' + value + '' WHERE a.ID IN (' + @ldb + ') ;'