Ryan Garrett
Ryan Garrett

Reputation: 7

SQL Return from list of strings via boolean

I have information that I am trying to report on that is currently categorized via a vlookup table in excel. This table would check the data coming from my days_past_due column in SQL database and return a string.

I.E. days_past_due = 5 would return the string '5-10 Days Past due'

I have about 8 different number ranges that would get their own string. Is their a way to hardcode this into the SQL query?

It is worth mentioning the string data is NOT in my database.

Upvotes: 0

Views: 171

Answers (2)

nish
nish

Reputation: 1221

Use the CASE function to achieve this.

  SELECT CASE 
    WHEN days_past_due = 5 THEN '5-10 Days Past due'
    WHEN ......
    ELSE <returndefaultcase>
    END
  FROM <tablename>

Upvotes: 2

Venkataraman R
Venkataraman R

Reputation: 12969

you can use CASE logic to get this.

SELECT CASE WHEN days_past_due = 5 THEN '5-10 Days Past due'
            WHEN ...
       END 
FROM YourTableName

Upvotes: 0

Related Questions