17,377
社区成员
发帖
与我相关
我的任务
分享
if object_id('[tb]') is not null drop table [tb]
go
create table [tb] (code int,bill_code nvarchar(6))
insert into [tb]
select 4010305,'001' union all
select 4010305,'005' union all
select 4010306,'007' union all
select 4010307,'009' union all
select 4010305,'003'
if object_id('dbo.f_str')is not null drop function dbo.f_str
go
CREATE FUNCTION dbo.f_str(@code int)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @r varchar(8000)
SET @r = ''
SELECT @r = @r + ',' + bill_code
FROM tb
WHERE code=@code
RETURN STUFF(@r, 1, 1, '')
END
GO
select dbo.f_str(4010305)
/*
001,005,003
(1 個資料列受到影響)
*/
WITH tmp AS
(
SELECT 'aa' ID, 11 VALUE FROM dual UNION ALL
SELECT 'bb' ID, 22 VALUE FROM dual
)
SELECT
wm_concat(ID||VALUE) "合并"
FROM tmp
select wm_concat(to_char(A)||to_char(B)) c1
from t1
select wm_concat(A||B) c1
from t1