想要将最后一个选择语句设置为 CURSOR
DECLARE @wec_AIMKEY numeric(17,5)
DECLARE @wec_IDENT varchar(15)
DECLARE @wec_QUANTITY numeric(20,2)
DECLARE @wec_BOM_UNIT varchar(30)
DECLARE @wec_Sort varchar(max)
DECLARE @wecMother_AIMKEY numeric(17,5)
set @wecMother_AIMKEY = 2158310.24613
DECLARE @wecSearchIDENT varchar(15)
set @wecSearchIDENT = '0712712';
-- ACHTUNG: der ; ist Wichtig ansonsten funktioniert die WITH nicht
-- Es werden alle Artikel Positionen gesucht
WITH Tree (X_PARENT_AIMKEY, AIMKEY, CATEGORY, X_POSITION, X_QUANTITY, BOM_UNIT, IDENT, SHORT_DESC, MATERIAL, STATUSKEY, CREATE_DATE, Depth, Sort)
AS
(
SELECT X_PARENT_AIMKEY, AIMKEY, CATEGORY, X_POSITION, X_QUANTITY, BOM_UNIT, IDENT, SHORT_DESC, MATERIAL, STATUSKEY, CREATE_DATE, 0 AS Depth, CONVERT(varchar(1000), X_PARENT_AIMKEY) AS Sort
FROM VIEW_XREF_CHILD_PART
where X_PARENT_AIMKEY = @wecMother_AIMKEY
UNION ALL
SELECT CT.X_PARENT_AIMKEY, CT.AIMKEY, CT.CATEGORY, CT.X_POSITION, CT.X_QUANTITY, CT.BOM_UNIT, CT.IDENT, CT.SHORT_DESC, CT.MATERIAL, CT.STATUSKEY, CT.CREATE_DATE, Parent.Depth + 1 AS Depth,
CONVERT(varchar(1000), Parent.Sort + '|' + CONVERT(varchar(1000),CT.X_PARENT_AIMKEY)) AS Sort
FROM VIEW_XREF_CHILD_PART CT
INNER JOIN Tree as Parent ON Parent.AIMKEY = CT.X_PARENT_AIMKEY
)
-- DECLARE wec_cr_quantity_sum CURSOR local forward_only read_only static FOR
-- ALL Positions
SELECT AIMKEY, IDENT, X_QUANTITY , BOM_UNIT, Sort
FROM Tree
where IDENT = @wecSearchIDENT
ORDER BY IDENT
==> DECLARE wec_cr_quantity_sum CURSOR local forward_only read_only static FOR dosent work
有什么想法我可以创建它吗?