日期:2014-05-17 浏览次数:20387 次
insert B(B01) select distinct stuff((select '-'+A02 from A order by A01 for xml path('')),1,1,'')
IF OBJECT_ID('Ta') IS NOT NULL
DROP TABLE Ta
GO
CREATE TABLE Ta
(A01 INT,
A02 VARCHAR(10)
)
INSERT Ta
SELECT 1,'a' UNION
SELECT 2,'b' UNION
SELECT 3,'c'
GO
IF OBJECT_ID('dbo.f_a') IS NOT NULL
DROP FUNCTION dbo.f_a
GO
CREATE FUNCTION f_a()
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @A02 VARCHAR(8000)
SELECT @A02=ISNULL(@A02+'-','')+ A02
From Ta a
RETURN @A02
END
SELECT B01=dbo.f_a()
/*
B01
-------------
a-b-c
(1 行受影响)
*/