Solved

Problem with IF Then  Else syntax in SQL stored procedure

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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 extract information from SQL Server on Database, Connection and Server properties

809 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