SQL Server Performance

simple a>b question

Discussion in 'General Developer Questions' started by allida77, May 8, 2003.

  1. allida77 New Member

    I have this section in a sp:

    IF @v_TotalNewAmt > @p_AquiredFor

    SET @p_ErrMsg = "Total Funded will go over 100% with this transaction.There is currently: "
    SET @p_TotalAmtLeft = @p_AquiredFor
    BEGIN
    ROLLBACK TRANSACTION
    RETURN @@ERROR
    END

    Both the "@v_" are money variable types. No matter what I do the code in the If statement is executed. I have even just tried "IF 1>2" but it still will return @p_TotalAmtLeft and stop the transaction. Also can you concatenate with TSQL? I am pretty new to TSQL so I am not sure what I am doing wrong.
  2. gaurav_bindlish New Member

    Are the data types for @v_TotalNewAmt and @p_AquiredFor same? I guess this is a typical case of data type mismatch.

    Yes you can concatenate in TSQL. Use SELECT @Some_Var=@Var1 + @var2 where @var1 and @var2 are char/varchar etc.

    Gaurav
  3. bambola New Member


    IF @v_TotalNewAmt > @p_AquiredFor
    -- this is the only line that will be executed according to the IF statement.
    SET @p_ErrMsg = "Total Funded will go over 100% with this transaction.There is currently: "

    -- this line is executed in any case.
    SET @p_TotalAmtLeft = @p_AquiredFor

    -- this block is executed in any case.
    BEGIN
    ROLLBACK TRANSACTION
    RETURN @@ERROR
    END
    I am supposing you are missing a BEGIN END somewhere... Could be?

    And yes, you can concatenate. watch the NULLS when you do so, or you will end up with NULL.

    Bambola.

Share This Page