Literal field Google Sheets QUERY
Asked Answered
D

2

7

Is there a way to add a literal field at the end of a Google Sheets QUERY function similar to what you can do in SQL?

e.g. =QUERY(A:C,"SELECT A, B, C, D AS 'CURRENT DATA'",0)

Thanks, Stefan

Dijon answered 4/8, 2016 at 14:45 Comment(0)
Z
7

Guess, you mean this:

=QUERY(A:C,"SELECT A, B, C, 'D' label 'D' 'CURRENT DATA'",0)

see more info here

The formula above will populate letter 'D', lebaled as 'CURRENT DATA'. If you want actual column D, then use range A:D:

=QUERY(A:D,"SELECT A, B, C, D label 'D' 'CURRENT DATA'",0)


More columns

Also possible to add more columns in any order. This formula would work:

=QUERY(A1:C4,"SELECT A, C, 'D', B, date '2016-05-30', 500 label 'D' 'CURRENT DATA', date '2016-05-30' 'MY DATE', 500 'MY NUMBER'",0)

here we select:

  • Column A
  • Column C
  • custom text
  • Column B
  • custom date
  • custom number
Zelda answered 4/8, 2016 at 14:51 Comment(0)
U
1

All I had to do was:

=QUERY(A:C,"SELECT A, B, C, 'D'",0)

This will give a literal D for all rows of your query.

Ureter answered 17/1 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.