Skip to content
Advertisement

How to use result of first query in second query where condition?

I have to select two tables data, One is PackageData and another is PackageDataDetails. Here is PackageData is Parent table and PackageDataDetails is child table.

See below code:

This code block is written in a stored procedure. Here, I didn’t want to rewrite the first query in where a condition of the second query.

I have to use this stored procedure in one API response to do things in one DB call only. Please share your idea to resolve this issue.

Advertisement

Answer

You can insert your first query data in table variable and then fetch the id from table variable in second query.Something like below.

Code:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement