转个类型select wm_concat(to_char(A)||to_char(B)) c1 from t1
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
sql server 怎么合并的啊大侠们
参考: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 個資料列受到影響) */
select wm_concat(A||B) c1
from t1
from t1
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
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 個資料列受到影響)
*/