How to simplify this long if else statement?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #16
    Can you give me some sample data?

    Comment

    • goodamr
      New Member
      • Jun 2007
      • 24

      #17
      2100694445,2007 ,3200,100,150
      2100694445,2008 ,3600,100,250
      2100694445,2009 ,2200,100,50
      2100694445,2010 ,4500,100,250

      Thanks.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #18
        So then you don't actually have fields named tax1, discount1, etc.?

        Then everything can be handled with a SQL statement. It depends on what SQL server you're using but for Microsoft SQL Server, I would do something like this
        Code:
        SELECT (SUM(price) - 
          SUM(CASE discount WHEN 100 THEN tax ELSE 0 END)
          ) AS total_price
        FROM Table1

        Comment

        • goodamr
          New Member
          • Jun 2007
          • 24

          #19
          I'm using Oracle 9

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #20
            Yeah, the query rabbit gave last is the best solution, you will need to make sure that syntax works in oracle, but otherwise, nice solution.

            Jared

            Comment

            Working...