6

I need to query a database which contains names of companies. I have list of around 50 names, for which i have to get the data. But I am unable to write a query using in command as there spaces in a name which are not being recognized. ex

select from sales where name in (`Coca Cola, `Pepsi)

This is giving me an error as 'Cola' is not being recognized. Is there a way to write such a query?

mollmerx
  • 648
  • 1
  • 5
  • 18
Mancunia89
  • 295
  • 1
  • 6
  • 16

2 Answers2

4

The spaces between the strings cause the interpreter to get confused. The `$() casts the list of characters to symbols.

q)t:([] a:1 2 3; name:`$("coca cola";"pepsi";"milk"))

q)select from t where name in `$("coca cola";"pepsi")
a name
-----------
1 coca cola
2 pepsi

You may also want to be careful of casing and either use consistently lower or upper case else that would cause unexpected empty results:

q)select from t where name in `$("Coca Cola";"Pepsi")
a name
------

q)select from t where upper[name] in upper `$("Coca Cola";"Pepsi")
a name
-----------
1 coca cola
2 pepsi
John at TimeStored
  • 1,305
  • 7
  • 9
0

You need to do something like the following:

select from sales where name in `$("Coca Cola";"Pepsi")
user1895961
  • 1,176
  • 9
  • 22