Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    Unanswered: Error while creating a stored procedure

    Pardon me if this is a noob thing (I am after all a noob).

    I am working with SQL Server 2005 Express and have written a query which works well in when run it in the managment console as a select query.

    When I try to create a stored procedure out of it, I get the following error:

    Code:
    Msg 102, Level 15, State 1, Procedure sp_SegmentationList_ByorderID, Line 20
    Incorrect syntax near ';'.
    Procedure is below:
    Code:
    USE [ARC_Test]
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE PROCEDURE [dbo].[sp_SegmentationList_ByorderID]
    @OrderID int
    
    AS 
    BEGIN
    	-- SET NOCOUNT ON added to prevent extra result sets from
    	-- interfering with SELECT statements.
    	SET NOCOUNT ON;
    
    SELECT      dbo.MailList.Donor_FName, dbo.MailList.Donor_LName, dbo.Items_History.OrderID, dbo.Orders_History.DriveID, dbo.MailList.MailID, 
                            dbo.MailList.DONOR_RACE, dbo.MailList.DONOR_SEX, dbo.MailList.DONOR_BDATE, dbo.MailList.DONOR_BTYPE, dbo.MailList.DONOR_TDONATS, 
                            dbo.MailList.isMilestone, dbo.MailList.Segment, dbo.MailList.DONOR_DDATE, dbo.Products_Select.ExcludeSegment
    FROM          dbo.Orders_History INNER JOIN
                            dbo.Items_History ON dbo.Orders_History.OrderID = dbo.Items_History.OrderID INNER JOIN
                            dbo.MailList ON dbo.Orders_History.OrderID = dbo.MailList.OrderID INNER JOIN
                            dbo.Products_Select ON dbo.Items_History.OrderItemCode = dbo.Products_Select.ProductID
    WHERE      
    dbo.Items_History.OrderID = @OrderID  
    AND dbo.Products_Select.ExcludeSegment = 0
    ;
    Any thoughts on this?

    Thanks.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    I see a BEGIN, but I don't see an END.

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    Quote Originally Posted by MCrowley View Post
    I see a BEGIN, but I don't see an END.
    Thank you sir... I suppose we like to think we can have a beginning without an end but SQL server doesn't.

    I am all set. Thanks for your help.

  4. #4
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    END is missing, but not sure why you need a BEGIN / END at all.

    Instead of adding an END, remove the BEGIN.
    Ken

    Maverick Software Design

    (847) 864-3600 x2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •