# Select \<QUERY TYPE Variable\>

**URL:** <https://www.singlestore.com/forum/t/select-query-type-variable/4918>\
**Category:** Procedural SQL\
**Created:** [August 26, 2022, 11:38am UTC](https://www.singlestore.com/forum/t/select-query-type-variable/4918 "2022-08-26T11:38:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prathap\_26](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/94ad74/32.png) [@prathap\_26](https://www.singlestore.com/forum/u/prathap_26)\
**Post date:** [August 26, 2022, 11:38am UTC](https://www.singlestore.com/forum/t/select-query-type-variable/4918/1 "2022-08-26T11:38:01Z")

</div>

Hi I have a query on QTV,  
create or replace procedure test11(ename\_in VARCHAR(55)

AS  
DECLARE  
q\_eids QUERY(eid INTEGER)=select employee\_id FROM EMPLOYEE where name=ename;

/\*  
alternative way if we wish to go in iterative way  
v\_eids ARRAY(RECORD(eid INTEGER)) = collect(q\_eids);  
the above captures the the results in an array of records but not array. Which I can’t pass in the where clause of the query.

\*/  
BEGIN  
q\_out QUERY(eid INTEGER  
ename VARCHAR(55),  
deptid INTEGER,  
dept\_name VARCHAR(55)  
) = SELECT e.eid,e.ename,e.depid,d.dept\_name  
FROM employee e inner join dept d on (e.deptid=d.deptid)  
WHERE eid in (select eid from q\_eids)  
…

…  
there are multiple queries like this.  
using (select eid from q\_eids)  
END;

whenever QTV calls/ collect is used the actual query will be triggered. instead I would like to execute the actual query once and only once, persists the results and use them.

The output persisted in that should be used across all the queries where the QTV is called.  
Could you please suggest me is there any ways that Singlestore provides( not allowed to use TEMP Tables).

With regards,  
Prathap Reddy G

---

<div class="post-metadata">

**Author:** ![arnaud](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arnaud](https://www.singlestore.com/forum/u/arnaud)\
**Post date:** [August 26, 2022, 3:43pm UTC](https://www.singlestore.com/forum/t/select-query-type-variable/4918/2 "2022-08-26T15:43:50Z")

</div>

Can you create a table and materialize the output of the query with insert into each table?
