|
Execute the following
script in Query Editor to count the number of purchase orders
issued by an employee:
USE AdventureWorks;
CREATE FUNCTION
fnPurchaseOrdersByEmployee(@EmpID INT)
RETURNS INT
AS
BEGIN
RETURN
(
SELECT COUNT(*) AS
'PurchaseOrdersByEmployee'
FROM Purchasing.PurchaseOrderHeader
WHERE EmployeeID = @EmpID
GROUP BY EmployeeID
)
END
-- SELECT EmployeeID, [PO-s] = dbo.fnPurchaseOrdersByEmployee(EmployeeID)
FROM HumanResources.Employee ORDER BY EmployeeID
|