Home > front end >  Can I use SQL CASE statement inside GoogleSheets QUERY?
Can I use SQL CASE statement inside GoogleSheets QUERY?

Time:01-14

How can I (or is it possible?) use something like CASE statement in T-SQL inside QUERY in Google spreadsheet?

I want to do something like this:

=QUERY(A6:AI,"select A,(CASE WHEN D>2.5 THEN 'Yes' ELSE 'No' END),E,C,J")

I want basically a custom column with Yes/No values based on other column. Is it possible?

EDIT: To better explain, I have data in table Existing table and I would like to transform it to the Transformed table using QUERY statement:

enter image description here

So I need something to say: if column D is empty, print No, otherwise print Yes. This has to be in the QUERY because it's not the last column, there will be more data after column Finished. So I have this:

=QUERY(A4:D,"Select A, B, (CASE WHEN D='' THEN 'No' ELSE 'Yes' END)") - But that doesn't work

Thank you for help,

CodePudding user response:

CASE & THEN are not supported in google's query language

try:

=INDEX({A6:A, IF(D6:D>2.5, "yes", "no"), E6:E, C6:C, J6:J})
  •  Tags:  
  • Related