Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 对于SQL Server中的每一行_Sql Server 2008 - Fatal编程技术网

Sql server 2008 对于SQL Server中的每一行

Sql server 2008 对于SQL Server中的每一行,sql-server-2008,Sql Server 2008,我得到了一张只有一列的表,例如:col1和5条记录 例:表名:表1 Col1 ------- aaaa bbbb cccc dddd eeee 我想基于col1值构建一个字符串,如下所示: set @stringVariable = ''aaaa', 'bbbb', 'cccc', 'dddd', 'eeee'' 如何做到这一点。谢谢布罗克,他工作得很好。。刚刚将其更改为@stringVariable=COALESCE(@stringVariable++++,''''++,'''++,'++

我得到了一张只有一列的表,例如:col1和5条记录

例:表名:表1

Col1
-------
aaaa
bbbb
cccc
dddd
eeee
我想基于col1值构建一个字符串,如下所示:

set @stringVariable = ''aaaa', 'bbbb', 'cccc', 'dddd', 'eeee''

如何做到这一点。

谢谢布罗克,他工作得很好。。刚刚将其更改为@stringVariable=COALESCE(@stringVariable++++,''''++,'''++,'++)+Business_键,因此我的结果是'035-7448-001-3854535','035-7448-001-3854536',…感谢Brock工作得很好。。刚刚将其更改为@stringVariable=COALESCE(@stringVariable++++,''''',''')+Business_键,因此我的结果是'035-7448-001-3854535','035-7448-001-3854536',。。。。。
DECLARE @stringVariable varchar (8000)
SET     @stringVariable = NULL  -- MUST be null to avoid leading comma.

SELECT
    @stringVariable     =  COALESCE (@stringVariable + '''' + ', ''', '') + Col1
FROM
    Table1

SET     @stringVariable = '''' + @stringVariable + ''''