insert into a table based on another tables numeric opperator field RRS feed

  • Question

  • User-1654626721 posted

    Hi Folks

    I have a insert into statement thats inserting my numbers from a numeric text box on my aspx page. I am choosing the Amount Type then putting in a a number.

    So i have a drop down that i select example Direct Charge then i enter 600.00 and click add it puts that in to the databse for me woot..

    I then put in say Misc Credit and enter 200.00 it inserts in that into the database woot.

    The look up table that has my amount types has a field called numeric opperator which is either + or - the Credit being a - and the Charge being a + then my stored procedure takes all my + numbers and adds them up and subtracts all the - numbers.

    I want to change that so that it actuall be inserted into the table as a - number form the start. So I want choose Misc Credit enter 200.00 and click add then my event says o yea thats a credit insert 200.00 as -200.00

    How can I do that?

    Example My AmountTypes

    AmountType         NumericOpperator

    Misc Charge                   +

    Misc Credit                     -

    I am inserting into a ReqDetailTable

    AmountType                Amount

    Misc Charge                 600.00

    Misc Credit                 -200.00

    Thank you for your help

    Thursday, November 11, 2010 2:48 PM


  • User-1654626721 posted

    I got it woot....

    insert into TempReqDetail (SessionID, AmountType, Amount)
    select @SessionIDNo, @AmountType, case when NumericOpperator = '-' then -1 else 1 end *@Amount
    from tblReqAmountTypes where AmountType = @AmountType

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 11, 2010 3:45 PM