字段1:
a
aa
e
g
想得到这么一个字符串 :“a,aa,e,g”
不用游标能行吗?
------解决方案--------------------
declare @sql varchar(8000)
set @sql= ' '
select @[email protected]+字段1 from table1
------解决方案--------------------
print @sql
------解决方案--------------------
create table temp(n varchar(10))
insert temp
select 'a '
union all select 'aa '
union all select 'e '
union all select 'g '
declare @str varchar(8000)
set @str= ' '
select @[email protected]+ ', '+n from temp
set @str = stuff(@str,1,1, ' ')
select @str
------解决方案--------------------
declare @str varchar(8000)
set @str= ' '
select @[email protected]+ ', '+字段1 from table1
print LEFT(@STR,LEN(@STR)-1)