快来看哪,这里有100分谁来拿?(唯一性字符串相加)

一个小问题:
有一个表,其中有一字段是city,存放城市名称,先定义一个变量@temp nvarchar(4000),如何用select语句将表中所有城市名取进@temp中?我写了一段代码,不好使,请指教。

declare @temp nvarchar(4000)
Set @temp = ' '
select distinct @temp = @temp +city from authors
select @temp

执行结果只取进去一个名字
---------------------------------------------------------------

declare @temp nvarchar(4000)
Set @temp = ' '
select @temp = @temp +city from (select distnict city from authors) AA
select @temp

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus