devxlogo

Using a stored procedure like a subquery

Question:
I’m trying to get something like this to work. How can I take the output of a stored procedure and use it in a subquery?

create procedure pcore asselect e_id from emails where e_id like ("%1%")create procedure pevalasselect e_id from emailswhere e_id in(execute pcore)

Answer:
The way to accomplish your task is to create a temp table with the same structure as the result set from your stored procedure. Then execute an insert into #temptable:

(    exec pcore)

You can then use your temp table in your subquery.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.