Optimization Question

  • Let's say I have the following value clause in an insert statement:

    "Column1" = (SELECT CASE WHEN SUM(ABS(t.Amount)*c.CalcInvestedAmount) IS NULL THEN 0 ELSE SUM(ABS(t.Amount)*c.CalcInvestedAmount) END

    Let's say the value IS NOT NULL, will the expression be executed twice?? i.e. the sum(ABS(t.amount)*c......)

    ?????

  • the case returns one of two values, 0 or the calculation.

    you could replace it with the same functionality:

    column1=isnull(SUM(ABS(t.Amount)*c.CalcInvestedAmount) ,0)

     

    a little less verbose, but with the same results.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Great.  The stored procedure I am working on has about 40 of these throughout.  I am hoping to chop some time off of it.

     

    Thanks for the response.

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

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