# Please advise, how to select with variable

**URL:** https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [May 24, 2015, 4:20pm UTC](https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868 "2015-05-24T16:20:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![LaiShun\_Mok](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@LaiShun\_Mok](https://forum.kx.com/u/LaiShun_Mok)
#### Post date: [May 24, 2015, 4:20pm UTC](https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868/1 "2015-05-24T16:20:00Z")

</div>

Dear all,  
&nbsp; &nbsp;

1. There is a table as same as the following

t:( eid:1 2 3 4 5;name:`A`B`C`D`E`F)

1. I have made a function which extract the first element of the list

f:{ x[0]}

a:f[“A1234567”]

1. I try to execute a select statement with the variable a, but it give a incorrect result.

select eid from t where name=a

1. I expect the result which is same as the below statement but it is not same as I expected

select eid from t where name=`A

Please help to advise what wrong with this statement.

Regards,

Nelson&nbsp;

---

<div class="post-metadata">

### Author: ![manni\_patel](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@manni\_patel](https://forum.kx.com/u/manni_patel)
#### Post date: [May 24, 2015, 4:59pm UTC](https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868/2 "2015-05-24T16:59:00Z")

</div>

your input:

“A1234567”

Is a list of char, not a list of symbols. Your name column is a symbol type. So try

a:f[`A`1`2`3`4`5`6`7]

---

<div class="post-metadata">

### Author: ![LaiShun\_Mok](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@LaiShun\_Mok](https://forum.kx.com/u/LaiShun_Mok)
#### Post date: [May 25, 2015, 1:50am UTC](https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868/3 "2015-05-25T01:50:00Z")

</div>

Hi&nbsp;manish,  
&nbsp; &nbsp;This is the requirement for data, I cannot change it. Thanks for your help.

Regards,

Nelson

---

<div class="post-metadata">

### Author: ![manni\_patel](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@manni\_patel](https://forum.kx.com/u/manni_patel)
#### Post date: [May 25, 2015, 12:04pm UTC](https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868/4 "2015-05-25T12:04:00Z")

</div>

ok, then just cast it?

… where name=`$a

(assuming a is an char atom)

---

<div class="post-metadata">

### Author: ![LaiShun\_Mok](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@LaiShun\_Mok](https://forum.kx.com/u/LaiShun_Mok)
#### Post date: [May 25, 2015, 1:58pm UTC](https://forum.kx.com/t/please-advise-how-to-select-with-variable/9868/5 "2015-05-25T13:58:00Z")

</div>

Hi manish,

&nbsp; &nbsp; Thank you.

Regards,

Nelson  
On Monday, May 25, 2015 at 7:04:50 PM UTC+8, manish patel wrote:

> ok, then just cast it?
> 
> … where name=`$a
> 
> (assuming a is an char atom)
