Solved

Problem with IF Then  Else syntax in SQL stored procedure

Posted on 2007-03-19
2
801 Views
Last Modified: 2012-08-14
What is wrong with this SQL statement?

ALTER  Procedure UpdateHODStatus

@HOD_Status varchar(1),
@HOD_Comment varchar(100),
@HOD_App_Date datetime,
@HODRequest_Status varchar(3),
@Request int

as
Begin
IF @HODRequest_Status = 'APP'
      BEGIN
            UPDATE Request
            SET HOD_Status = @HOD_Status,
                  HOD_Comment = @HOD_Comment,
                  HOD_App_Date = @HOD_App_Date,
            Request_Status = @HODRequest_Status
            Where Request_Number = @Request

            INSERT INTO PO_Request
            (Request_Number, PO_Date)
            VALUES (@Request, @HOD_App_Date
      
      END

ELSE
BEGIN
      UPDATE Request
      SET HOD_Status = @HOD_Status,
            HOD_Comment = @HOD_Comment,
            HOD_App_Date = @HOD_App_Date,
            Request_Status = @HODRequest_Status
      Where Request_Number = @Request
END
END

Here is error I get:
Server: Msg 156, Level 15, State 1, Procedure UpdateHODStatus, Line 24
Incorrect syntax near the keyword 'END'.
0
Comment
Question by:flg8tor96
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 18751919
ALTER  Procedure UpdateHODStatus

@HOD_Status varchar(1),
@HOD_Comment varchar(100),
@HOD_App_Date datetime,
@HODRequest_Status varchar(3),
@Request int

as
Begin
      IF @HODRequest_Status = 'APP'
      BEGIN
            UPDATE Request
            SET HOD_Status = @HOD_Status,
            HOD_Comment = @HOD_Comment,
            HOD_App_Date = @HOD_App_Date,
            Request_Status = @HODRequest_Status
            Where Request_Number = @Request
            
            INSERT INTO PO_Request
            (Request_Number, PO_Date)
            VALUES (@Request, @HOD_App_Date ) ----------------missing ')'
      
      END
      
      ELSE
      BEGIN
            UPDATE Request
                  SET HOD_Status = @HOD_Status,
                  HOD_Comment = @HOD_Comment,
                  HOD_App_Date = @HOD_App_Date,
                  Request_Status = @HODRequest_Status
            Where Request_Number = @Request
      END
END
0
 

Author Comment

by:flg8tor96
ID: 18751927
thanks
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question