简单问题

accpyy 2006-08-18 11:22:37
declare @aa as varchar(100)
set @aa = ''
select left(0,len((@aa = @aa + ck_lxmc + '/'),-1)) as b from dbo.t_cklx

说这个语法有问题 请指点!想实现多条记录合并显示
如: ck_lxmc
记录1 a
记录1 b
记录1 c
得到结果: a/b/c
...全文
190 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyxfly 2006-08-18
  • 打赏
  • 举报
回复
create table t_cklx
(
记录 varchar(20),
ck_lxmc varchar(10)
)
insert t_cklx
select '记录1','a' union all
select '记录1','b' union all
select '记录1','c'
select * from t_cklx
go
create function Gettxt(@id varchar(20))
returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s=''
select @s=@s+'/'+ck_lxmc from t_cklx where 记录=@id
return @s
end
go
select 记录,dbo.Gettxt(记录) 记录集 from t_cklx group by 记录
vfssqs 2006-08-18
  • 打赏
  • 举报
回复
存储过程,游标。
fcuandy 2006-08-18
  • 打赏
  • 举报
回复
需要函数解决.当然写复杂的动态语句也可以的,就是太麻烦了.
xyxfly 2006-08-18
  • 打赏
  • 举报
回复
写个函数
参考
create table csdn
(
id int,
txt varchar(10)
)
insert csdn
select 1,'a' union all
select 1,'b' union all
select 1,'c' union all
select 2,'aa' union all
select 2,'bb' union all
select 2,'cc' union all
select 3,'aaa' union all
select 3,'bbb'
select * from csdn
go
create function Gettxt(@id int)
returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s=''
select @s=@s+txt from csdn where id=@id
return @s
end
go
select id,dbo.Gettxt(id) txt from csdn group by id
achongsky 2006-08-18
  • 打赏
  • 举报
回复
查询的结果是记录集,用循环或者游标实现。

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧