我有以下select语句,它返回我想要的内容:
DECLARE @result varchar(max) = ''
SELECT @result += (result.Fullname + '<br/>')
FROM (SELECT DISTINCT Fullname
FROM Providers
WHERE Status='A') as result
select substring(@result, 0, len(@result) - 4)
唯一的问题是,我希望此查询的输出显示为较大的select语句中的列条目。
EG。
SELECT
Column AS [AColumnName],
SELECT @result += (result.Fullname + '<br/>')
FROM (SELECT DISTINCT Fullname
FROM Providers
WHERE Status='A') as result
select substring(@result, 0, len(@result) - 4) as [LenderList]
FROM
Table
但我目前收到错误:关键字&#39; SELECT&#39;附近的语法不正确。 指向第4行的错误
有什么想法吗?
答案 0 :(得分:2)
您需要在SQL Server中进行聚合字符串连接。子查询已经有很多答案,但为了省去麻烦:
SELECT Column AS [AColumnName],
STUFF((SELECT DISTINCT '<br/>' + Fullname
FROM Providers
WHERE Status = 'A'
FOR XML PATH (''), TYPE
).value('.', 'varchar(max)'
), 1, 5, ''
) as result
FROM Table;
使用该类型很重要,因为您的字符串具有特殊的XML字符。
答案 1 :(得分:0)
你能简单地用2个语句运行吗?
await Task.WhenAll(downloadTasks);
答案 2 :(得分:0)
哪个数据库?如果你可以用于xml,那就像......
select substring(a.innards, 0, len(a.innards) - 4) as [LenderList]
from
(
SELECT innards = STUFF(
(SELECT DISTINCT Fullname + '</br>'
FROM Providers
WHERE [Status] = 'A'
FOR XML PATH(''), TYPE).value('.[1]', 'nvarchar(max)')
, 1
, 0
, '')
) a