Advertisement

12.29.2004 at 06:46AM PST, ID: 21256314
[x]
Attachment Details

USing nested if then else in Stored procedure

Asked by LuckyLucks in MS SQL Server

Tags: else, stored, procedure

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/(SELECT 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)+isnull(@C,0)+isnull(@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
[+][-]12.29.2004 at 06:54AM PST, ID: 12919139

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 06:55AM PST, ID: 12919153

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.29.2004 at 07:00AM PST, ID: 12919189

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: else, stored, procedure
Sign Up Now!
Solution Provided By: acperkins
Participating Experts: 3
Solution Grade: A
 
 
[+][-]12.29.2004 at 07:04AM PST, ID: 12919227

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 07:55AM PST, ID: 12919673

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.29.2004 at 08:02AM PST, ID: 12919741

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32