Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    7

    Unanswered: error ini this procedure?

    create table Billings (
    BankerID INTEGER,
    BillingNumber INTEGER,
    BillingDate datetime,
    BillingTotal INTEGER,
    TermsID INTEGER,
    BillingDueDate datetime ,
    PaymentTotal INTEGER,
    CreditTotal INTEGER

    );


    INSERT INTO Billings VALUES (1, 1, '2005-01-22', 165, 1,'2005-04-22',123,321);
    INSERT INTO Billings VALUES (2, 2, '2001-02-21', 165, 1,'2002-02-22',123,321.);
    INSERT INTO Billings VALUES (3, 3, '2003-05-02', 165, 1,'2005-04-12',123,321);
    INSERT INTO Billings VALUES (4, 4, '1999-03-12', 165, 1,'2005-04-18',123,321);
    INSERT INTO Billings VALUES (5, 5, '2000-04-23', 165, 1,'2005-04-17',123,321);
    INSERT INTO Billings VALUES (6, 6, '2001-06-14', 165, 1,'2005-04-18',123,321);
    INSERT INTO Billings VALUES (7, 7, '2002-07-15', 165, 1,'2005-04-19',123,321);
    INSERT INTO Billings VALUES (8, 8, '2003-08-16', 165, 1,'2005-04-20',123,321);
    INSERT INTO Billings VALUES (9, 9, '2004-09-17', 165, 1,'2005-04-21',123,321);
    INSERT INTO Billings VALUES (0, 0, '2005-10-18', 165, 1,'2005-04-22',123,321);


    CREATE PROC spInsertBilling
    @BankerID int, @BillingNumber varchar(50),
    @BillingDate smalldatetime, @BillingTotal money,
    @TermsID int, @BillingDueDate smalldatetime
    AS
    DECLARE @ErrorVar int
    INSERT Billings (BankerID)
    VALUES (@BankerID)
    SET @ErrorVar = @@ERROR
    IF @ErrorVar <> 0
    BEGIN
    IF @ErrorVar = 547
    PRINT 'Not a valid BankerID!'
    ELSE
    PRINT 'An unknown error occurred.'
    RETURN @ErrorVar
    END

    DECLARE @ReturnVar int
    EXEC @ReturnVar = spInsertBilling
    799,'ZXK-799','2002-07-01',299.95,1,'2001-08-01'
    PRINT 'Return code was: ' + CONVERT(varchar,@ReturnVar)

    drop PROC spInsertBilling;

    drop table Billings;


    ******************************
    When I compile this database, i found some error like below:

    Msg 111, Level 15, State 1, Procedure spInsertBilling, Line 44
    'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
    Msg 178, Level 15, State 1, Procedure spInsertBilling, Line 53
    A RETURN statement with a return value cannot be used in this context.


    can you tell me what is wrong with my source??
    thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Australia
    Posts
    113
    Absolutely nothing - just don't execute it all in one hit, or put a GO between each section - eg a go after inserting data, go after creating the procedure, Go after executing the procedure.

Posting Permissions

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