Print error message

  • Hi, here is the script below:

    In this script I am matching voucher type and according to that I am inserting the data in the table. But when I write wrong voucher type script keeps executing so I want to print to stops the execution of the script and prints a error message if voucher type is not matched.

    Declare @vouchertype varchar(20) = 'Value Based,

    @denomination int,

    @userid int,

    @voucherstatus int,

    @transactionID varchar(20),

    @quantity int = 1,

    @count int =1,

    @innercount int =1,

    @leaf int =10,

    @max-2 int

    WHILE @count <= @quantity

    BEGIN

    WHILE @innercount <= @leaf

    BEGIN

    SET @max-2 = (select vouchervaluebased from gv_maxvouchervalue)

    SET @transactionID = (select vouchertransactionID from gv_maxvouchervalue)

    if @vouchertype = (select VoucherType from GV_VoucherType where VoucherType = 'Value Based')

    BEGIN

    INSERT INTO GV_Booklet

    VALUES

    (

    @leaf,

    500,

    1,

    'VB' + Replace( Str( @max-2+1, 7), ' ', '0') ,

    @quantity,

    GETDATE(),

    GETDATE(),

    DATEADD(MM,6,GETDATE()),

    1,

    1,

    'TRN' + Replace( Str( @transactionID + 1, 7), ' ', '0')

    )

    SET @innercount = @innercount + 1

    UPDATE gv_maxvouchervalue

    SET vouchervaluebased = @max-2 + 1

    END

    END

    SET @innercount = 1

    SET @count = @count + 1

    UPDATE gv_maxvouchervalue

    SET vouchertransactionID = @transactionID + 1

    END

    select * from GV_Booklet

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Split thread. Original here.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • ChrisM@Work (3/18/2013)


    Split thread. Original here.

    Hey Chris I am not getting what you want to point out by this :w00t:

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply