I'm just getting started learning SQL Server Management Studio. I'm familiar with building nested queries in Access, e.g.:
Query1
(get a data set)
select t1.a,t2.b,t1.abc,t2.def from tbl_FNA t1
inner join
tbl_DMZ t2 on
t1.b=t2.b
Query2
(return only the rows from Query1
with the minimum value of b
)
select q1.* from Query1 q1
inner join
(select a,min(b) as min_b from Query1 group by a) q2
on
q1.a=q2.a
and
q1.b=q2.min_b
This makes it easier to debug the code because if there's something wrong with Query1
, I only have to change it in one place instead of 3 places.
I'm aware that if I have write access to the database, I can create views and/or stored procedures that can help with this. But in this case, I have read-only access.
Is there a way in SSMS that I can save a query and then refer to that query by name inside another query?