Select results based on a value within a table

  • Morning All,

    Iā€™m stumped on a sqlquery and thought I might ask for some help. first time I'm trying this.

    I'm trying to build a select query that pulls fields from 3 related tables (transactions,Destinatin,Rates)  the Rates table has two particular columns [Rate A] and [Rate B] and I need to select either one of these based on a value in the Transaction table [Tonnage] column. So basically if the tonnage is <= 15 then select [Rate A] if not [Rate B]

    I've joined the 3 tables , I'm think I should use a subquery in a case like below but I'm not sure how to put that together, or whether this is the best way to do it.

    Case when tonnage >= 15 then subquery1 else subquery2

    End

    -------------------------------------------------------------------
    I've attached sample of my script.

    Any help is much appreciated.

  • I think this is what you're after.
    CASE WHEN Tonnage <= 15 THEN [Rate A] ELSE [Rate B] END

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thank you for your quick reply....yes that worked like a dream , I wish I had come here earlier. 

    Thanks ! šŸ˜€

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 10 posts - 1 through 9 (of 9 total)

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