create function fun_combName1(@teamname varchar(32))
returns varchar(4000)
as
begin
declare @temp varchar(4000)
set @temp = ''
select @temp = @temp+';'+姓名 from 员工 where 部门号 = @teamname
set @temp = stuff(@temp,1,1,'')
return @temp
end--执行查询语句:
select 部门号,姓名 = dbo.fun_combName(部门号) from 员工 group by 部门号
order by 部门号; 在PLSQL里面执行的时候说是函数无效……
换成:select
姓名,部门号
stuff((select ','+convert(varchar(10),部门号) from 员工 b
where 姓名=a.姓名
for xml path('')),1,1,'')
from 员工 a
group by 部门号,姓名
之后说缺少表达式,求大神解救啊~~~~~TUT
returns varchar(4000)
as
begin
declare @temp varchar(4000)
set @temp = ''
select @temp = @temp+';'+姓名 from 员工 where 部门号 = @teamname
set @temp = stuff(@temp,1,1,'')
return @temp
end--执行查询语句:
select 部门号,姓名 = dbo.fun_combName(部门号) from 员工 group by 部门号
order by 部门号; 在PLSQL里面执行的时候说是函数无效……
换成:select
姓名,部门号
stuff((select ','+convert(varchar(10),部门号) from 员工 b
where 姓名=a.姓名
for xml path('')),1,1,'')
from 员工 a
group by 部门号,姓名
之后说缺少表达式,求大神解救啊~~~~~TUT
A 30
A 40
A 50
B 40
C 10效果变成:A 20,30,40,50
B 40
C 10
select distinct a.name name,a.deptcode deptcode from table a where a.deptcode in (10,20) order by a.deptcode
) group by deptcode
SELECT BT.BASE_DEP_CODE,ZH_CONCAT(BT.NAME) FROM TABLE BT
GROUP BY BT.BASE_DEP_CODE