another IIf function question

  • Hi there i have another IIf function problem. I am trying to work out the VAT amount for sold stock units and am hoping someone can tell me the sql equivalent to the VBA: 

    VAT: IIf([SIV]>[ActualSellingPrice],([SIV]*0),IIf([New]<0,[ActualSellingPrice]*(7/47),([ActualSellingPrice]-[SIV])*(7/47)))

    Thanks

    Armo 

  • Hi Niall,

       R u looking for the sql query with case else end clause?

    Nivedita

     

     

  • Hi Nivedita

    Yes please,

    I thought it was to do with case and else end, but am having difficulty putting the sql together.

    Niall

  • SELECT CASE WHEN SIV > ActualSellingPrice THEN 0 ELSE CASE WHEN NEW < 0 THEN ActualSellingPrice * 7 / 47 ELSE (ActualSellingPrice - SIV) * 7 / 47 END END AS ColName FROM dbo.YourTable

  • Thanks again, it all starts to make sense when i see the correct syntax

  • Check the books online. It's really like "if/else" but with a mix of "select case" .

Viewing 6 posts - 1 through 5 (of 5 total)

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