Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE FUNCTION Sales.ufn_SalesByStore(@storeid int) -- izmjenejno malo sa WHERE i sad je tocno valjda
- RETURNS TABLE
- AS
- RETURN
- (
- SELECT p.ProductID, p.Name, sum(sod.LineTotal) Total
- FROM Production.Product p
- join Sales.SalesOrderDetail sod on p.ProductID = sod.ProductID
- join Sales.SalesOrderHeader soh on sod.SalesOrderID = soh.SalesOrderID
- join Sales.Customer c on soh.CustomerID = c.CustomerID
- where c.StoreID = @storeid
- group by p.ProductID, P.Name
- )
- select * from Sales.ufn_SalesByStore1(934)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement