Complecated Sql query

  • Hello Guys, I am writing a complecated sql query and I would really appreciate if you can help me to figure out.

    The logic is below but that needs to be part of Select statement.

    If (FinancialStatus = "Customer")

    then Amount = 0

    else If (Status = "Hold")

    then MinPrice = Mintransferprice

    else If (OriginalCost > 0)

    then OCost = (originalCost * MinPricePercentage /100)

    else If (BeforeActivationPrice > 0 )

    then BCost = (BeforeActivationPrice * MinPricePercentage /100)

    Upto this point is easy. I can use Case Output when xxx then yyy when aaa then bbbb but my problem is

    I need to find Maximum value of Amount, MinPrice, OCost and BCost

    -------------------

    This all needs to be done in a single select statement.

    Thanks in advance for your help.

  • Doable, but with a bit of help from you.

    Please read the following article and provide us create table, sample data and ur expected output based off of the sample data

    How to post questions[/url]

  • Hi,

    I agree with the ColdCoffee.

    Also I could not understand very well.

    Maybe you can use this:

    MAX( case ... ) as MaxAmount

    Hope this helps.

  • I figured out the solution. Thanks for the help.

    case when t.FinancialStatus = ''Customer'' then 0 else

    case when (cfc.OriginalCostBase * ccc.mintransferpricepercentage /100) > (cfc.beforeactivationcostusd * ccc.mintransferpricepercentage /100) and

    (cfc.OriginalCostBase * ccc.mintransferpricepercentage /100) > (ccc.mintransferpriceusd)

    then (cfc.OriginalCostBase * ccc.mintransferpricepercentage /100)

    else

    case when (cfc.beforeactivationcostusd * ccc.mintransferpricepercentage /100) > (ccc.mintransferpriceusd)

    then (cfc.beforeactivationcostusd * ccc.mintransferpricepercentage /100)

    else

    (ccc.mintransferpriceusd)

    end

    end

    End as [MinTransferPrice]

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

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