Solved

Problem with IF Then  Else syntax in SQL stored procedure

Posted on 2007-03-19
2
788 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now