6> CREATE PROC spTriangular
7> @ValueIn int,
8> @ValueOut int OUTPUT
9> AS
10> DECLARE @InWorking int
11> DECLARE @OutWorking int
12> IF @ValueIn != 1
13> BEGIN
14> SELECT @InWorking = @ValueIn - 1
15> EXEC spTriangular @InWorking, @OutWorking OUTPUT
16>
17> SELECT @ValueOut = @ValueIn + @OutWorking
18> END
19> ELSE
20> BEGIN
21> SELECT @ValueOut = 1
22> END
23> RETURN
24> GO
1>
2> DECLARE @WorkingOut int
3> DECLARE @WorkingIn int
4> SELECT @WorkingIn = 5
5> EXEC spTriangular @WorkingIn, @WorkingOut OUTPUT
6>
7> PRINT CAST(@WorkingIn AS varchar) + ' Triangular is ' + CAST(@WorkingOut AS varchar)
8> GO
5 Triangular is 15
1>
2> drop PROC spTriangular;
3> GO
|