Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.53 KB | None | 0 0
  1. CREATE FUNCTION Sales.ufn_SalesByStore(@storeid int)                -- izmjenejno malo  sa WHERE i sad je tocno valjda
  2. RETURNS TABLE
  3. AS
  4. RETURN
  5. (
  6.        
  7.         SELECT p.ProductID, p.Name, sum(sod.LineTotal) Total
  8.  
  9.         FROM Production.Product p
  10.         join Sales.SalesOrderDetail sod on p.ProductID = sod.ProductID
  11.         join Sales.SalesOrderHeader soh on sod.SalesOrderID = soh.SalesOrderID
  12.         join Sales.Customer c on soh.CustomerID = c.CustomerID
  13.         where c.StoreID = @storeid
  14.         group by p.ProductID, P.Name
  15. )
  16.  
  17. select * from Sales.ufn_SalesByStore1(934)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement