• I think you will find that this is the problem

    SET @vouchertype = LTRIM(RIGHT(@vouchertype,LEN(@vouchertype)-CHARINDEX(' ',@vouchertype,1)));

    As you seem to be taking Right N characters, in @vouchertype, and over Writing it so If @VoucherType='Value Discount' you are then changing @vouchertype to 'Discount' so @VoucherType != 'Value Discount'

    You also have a Print Statement between the IF EXISTS and the BEGIN, I believe that this will then cause everything in the Next BEGIN/END batch to execute regardless of the outcome of the EXISTS.

    Eg

    IF EXISTS(Select 1)

    PRINT 'TRUE'

    BEGIN

    Print 'FALSE'

    END

    Both true and False are printed. Is this intended behaviour?

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices