SQL Server - use columns from the main query in the subquery SQL Server - use columns from the main query in the subquery sql-server sql-server