Sql-server – Use a value from another query in a query

sql server 2014

I have query 1 which has a result with one row and one column, it shows the period our system is in.

I want to use that value from query 1 in another query called query 2

So for example it would be something like

Select * FROM MyTable WHERE Period = (Period in Query 1)

How could I do this?

Best Answer

You can use a subquery for this so:

Select * FROM MyTable WHERE Period = (
 SELECT period FROM someothertable WHERE ...)

There are numerous other ways of doing this however, so it would need research and testing to find the most efficient way.