Hi Experrts,
I am having an issue with the correct syntax of the nested if then else in a stored procedure. I get a syntax error or access violation :code 0. please help!
CREATE PROCEDURE [dbo].[SP]
@ID nVarChar(10) AS
DECLARE @A tinyint, @B tinyint, @C tinyint, @D tinyint, @E tinyint,
@F money, @G real,@H real, @I real,@newHoldRatio float, @chk tinyint
DECLARE c1 CURSOR FOR
SELECT A,B,C,D,E,F,G,H,I,Hold/(SE
LECT AVG(tbl.Hold) AS AVGHold FROM tbl) AS hp FROM tbl WHERE ID=@ID
OPEN c1
FETCH NEXT FROM c1
INTO @A, @B, @C, @D, @E , @F,@G,@H,@I,@newHoldRatio
WHILE @@FETCH_STATUS = 0
BEGIN
SET @chk=isnull(@A,0)+isnull(@
B,0)+isnul
l(@C,0)+is
null(@D,0)
+isnull(@E
,0)
if @chk=5
{
if @F > @G THEN SET @H = 1
else if @G > @I THEN SET @H = 2
else SET @H=3
}
else
PRINT 'Chk is not 5'
FETCH NEXT FROM c1
INTO @A, @B, @C, @D, @E , @F,@G,@H,@I,@newHoldRatio
END
GO
Start Free Trial