请帮助我,我创建了这个存储过程:
ALTER PROCEDURE [dbo].[objueb]
@UebKat varchar(500) = NULL,
@Multikz nchar(1) = "|",
@Objekte nchar(999) = NULL OUTPUT
AS
BEGIN
SELECT DISTINCT
St2.Ueberk,
substring((SELECT @Multikz + ST1.ObjektId AS [text()]
FROM dbo.DtaVor ST1
WHERE ST1.Ueberk = ST2.Ueberk
ORDER BY ST1.Ueberk
FOR XML PATH ('') ), 2, 1000) [Objekte]
FROM
dbo.DtaVor ST2
WHERE
Ueberk = @Uebkat
END
结果是:
|----------------|---------------------------------------------|
| Ueberk | Objekte |
|----------------|---------------------------------------------|
| BLX HS | 10002533 |10001132 |10001560 |10002156 |
|----------------|---------------------------------------------|
结果总是一行。
我想在参数(@Objekte
)
谢谢!
答案 0 :(得分:0)
假设DBMS是基于FOR XML PATH
的使用的SQL Server。您只需将结果分配给变量:
ALTER PROCEDURE [dbo].[objueb]
@UebKat varchar(500) = NULL,
@Multikz nchar(1) = "|",
@Objekte nchar(999) = NULL OUTPUT
AS
BEGIN
SELECT @Objekte = Objekte
FROM
(SELECT DISTINCT
St2.Ueberk,
substring((SELECT @Multikz + ST1.ObjektId AS [text()]
FROM dbo.DtaVor ST1
WHERE ST1.Ueberk = ST2.Ueberk
ORDER BY ST1.Ueberk
FOR XML PATH ('') ), 2, 1000) AS [Objekte]
FROM
dbo.DtaVor ST2
WHERE
Ueberk = @Uebkat) o
END
DISTINCT
是否需要确保一行(Ueberk
是主键?)?如果没有,您可以删除子选择:
ALTER PROCEDURE [dbo].[objueb]
@UebKat varchar(500) = NULL,
@Multikz nchar(1) = "|",
@Objekte nchar(999) = NULL OUTPUT
AS
BEGIN
SELECT
@Objekte = substring((SELECT @Multikz + ST1.ObjektId AS [text()]
FROM dbo.DtaVor ST1
WHERE ST1.Ueberk = ST2.Ueberk
ORDER BY ST1.Ueberk
FOR XML PATH ('') ), 2, 1000)
FROM
dbo.DtaVor ST2
WHERE
Ueberk = @Uebkat
END