代码
1 SET ANSI_NULLS ON
2 GO
3 SET QUOTED_IDENTIFIER ON
4 GO
5
6 CREATE FUNCTION [dbo].[fn_GetSubCasNoTree](@CAS_NO VARCHAR(20))
7 RETURNS @CAS TABLE
8 (
9 CAS_NO VARCHAR(20) COLLATE DATABASE_DEFAULT,这个不加SQL2000会报错。
10 LEVEL INT
11 )
12
13 AS
14 BEGIN
15 DECLARE @LEVEL int
16 SET @LEVEL = 1
17 INSERT INTO @CAS SELECT @CAS_NO , @LEVEL
18 WHILE @@ROWCOUNT > 0
19 BEGIN
20 SET @LEVEL = @LEVEL + 1
21 INSERT INTO @CAS SELECT A.CAS_NO , @LEVEL
22 FROM CASN A , @CAS B
23 WHERE A.UP = B.CAS_NO and B.LEVEL = @LEVEL - 1
24 END
25 RETURN
26 END
2 GO
3 SET QUOTED_IDENTIFIER ON
4 GO
5
6 CREATE FUNCTION [dbo].[fn_GetSubCasNoTree](@CAS_NO VARCHAR(20))
7 RETURNS @CAS TABLE
8 (
9 CAS_NO VARCHAR(20) COLLATE DATABASE_DEFAULT,这个不加SQL2000会报错。
10 LEVEL INT
11 )
12
13 AS
14 BEGIN
15 DECLARE @LEVEL int
16 SET @LEVEL = 1
17 INSERT INTO @CAS SELECT @CAS_NO , @LEVEL
18 WHILE @@ROWCOUNT > 0
19 BEGIN
20 SET @LEVEL = @LEVEL + 1
21 INSERT INTO @CAS SELECT A.CAS_NO , @LEVEL
22 FROM CASN A , @CAS B
23 WHERE A.UP = B.CAS_NO and B.LEVEL = @LEVEL - 1
24 END
25 RETURN
26 END