You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/t-sql/queries/from-transact-sql.md
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -403,15 +403,15 @@ ON (p.ProductID = v.ProductID);
403
403
## Using APPLY
404
404
Both the left and right operands of the APPLY operator are table expressions. The main difference between these operands is that the *right_table_source* can use a table-valued function that takes a column from the *left_table_source* as one of the arguments of the function. The *left_table_source* can include table-valued functions, but it cannot contain arguments that are columns from the *right_table_source*.
405
405
406
-
The APPLY operator works in the following way to produce the table source for the FROM clause:
406
+
The APPLY operator works in the following way to produce the table source for the FROM clause:
407
407
408
408
1. Evaluates *right_table_source* against each row of the *left_table_source* to produce rowsets.
409
409
410
-
The values in the *right_table_source* depend on *left_table_source*. *right_table_source* can be represented approximately this way: `TVF(left_table_source.row)`, where `TVF` is a table-valued function.
410
+
The values in the *right_table_source* depend on *left_table_source*. *right_table_source* can be represented approximately this way: `TVF(left_table_source.row)`, where `TVF` is a table-valued function.
411
411
412
412
2. Combines the result sets that are produced for each row in the evaluation of *right_table_source* with the *left_table_source* by performing a UNION ALL operation.
413
413
414
-
The list of columns produced by the result of the APPLY operator is the set of columns from the *left_table_source* that is combined with the list of columns from the *right_table_source*.
414
+
The list of columns produced by the result of the APPLY operator is the set of columns from the *left_table_source* that is combined with the list of columns from the *right_table_source*.
415
415
416
416
## Using PIVOT and UNPIVOT
417
417
The *pivot_column* and *value_column* are grouping columns that are used by the PIVOT operator. PIVOT follows the following process to obtain the output result set:
@@ -573,32 +573,35 @@ FROM Sales.Customer TABLESAMPLE SYSTEM (10 PERCENT) ;
573
573
```
574
574
575
575
### K. Using APPLY
576
-
The following example assumes that the following tables with the following schema exist in the database:
There is also a table-valued function, `GetReports(MgrID)` that returns the list of all employees (`EmpID`, `EmpLastName`, `EmpSalary`) that report directly or indirectly to the specified `MgrID`.
585
+
The `GetReports`table-valued function, returns the list of all employees that report directly or indirectly to the specified `MgrID`.
585
586
586
-
The example uses `APPLY` to return all departments and all employees in that department. If a particular department does not have any employees, there will not be any rows returned for that department.
587
+
The example uses `APPLY` to return all departments and all employees in that department. If a particular department does not have any employees, there will not be any rows returned for that department.
FROM Departments d CROSS APPLY dbo.GetReports(d.DeptMgrID) ;
591
+
FROM Departments d
592
+
CROSS APPLY dbo.GetReports(d.DeptMgrID) ;
591
593
```
592
594
593
-
If you want the query to produce rows for those departments without employees, which will produce null values for the `EmpID`, `EmpLastName` and `EmpSalary` columns, use `OUTER APPLY` instead.
595
+
If you want the query to produce rows for those departments without employees, which will produce null values for the `EmpID`, `EmpLastName` and `EmpSalary` columns, use `OUTER APPLY` instead.
FROM Departments d OUTER APPLY dbo.GetReports(d.DeptMgrID) ;
599
+
FROM Departments d
600
+
OUTER APPLY dbo.GetReports(d.DeptMgrID) ;
598
601
```
599
602
600
603
### L. Using CROSS APPLY
601
-
The following example retrieves a snapshot of all query plans residing in the plan cache, by querying the `sys.dm_exec_cached_plans` dynamic management view to retrieve the plan handles of all query plans in the cache. Then the `CROSS APPLY` operator is specified to pass the plan handles to `sys.dm_exec_query_plan`. The XML Showplan output for each plan currently in the plan cache is in the `query_plan` column of the table that is returned.
604
+
The following example retrieves a snapshot of all query plans residing in the plan cache, by querying the `sys.dm_exec_cached_plans` dynamic management view to retrieve the plan handles of all query plans in the cache. Then the `CROSS APPLY` operator is specified to pass the plan handles to `sys.dm_exec_query_plan`. The XML Showplan output for each plan currently in the plan cache is in the `query_plan` column of the table that is returned.
0 commit comments