Solved

Problem with IF Then  Else syntax in SQL stored procedure

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

752 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