Solved

Problem with IF Then  Else syntax in SQL stored procedure

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

816 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

11 Experts available now in Live!

Get 1:1 Help Now