sql server - Apparently, Stored Procedure syntax is harder to understand than I anticipated -
so i'm trying replicate query stored procedure.
use thisdb select firstname + ' ' + lastname fullname , sum(unitprice * quantity) 'total sales', year(orderdate) salesyear employees e join orders o on o.employeeid = e.employeeid join [order details] od on od.orderid = o.orderid group lastname +' ' +firstname, year(orderdate) order 'total sales' desc
edit: noticed old query gonna fail, don't change /edit
unfortunately, haven't found examples me translate know queries stored procedure syntax. here understand far:
use thisdb; go create procedure empsalesbyyear @emp out begin set emp = (select employees.firstname, employees.lastname , totalsales = sum([order details].unitprice * [orderdetails].quantity), year(orders.orderdate) salesyear employees e join orders o on o.employeeid = e.employeeid join [order details] od on od.orderid = o.orderid group firstname , lastname order totalsales desc) end go
predictably, sql server
give me finger when type in. . .
my goal here stored procedure takes 0 input parameters , outputs table first query.
thanks.
further comment, can do:
create procedure proc_getempsalesbyyear select firstname + ' ' + lastname fullname , sum(unitprice * quantity) 'total sales', year(orderdate) salesyear thisdb..employees e join thisdb..orders o on o.employeeid = e.employeeid join thisdb..[order details] od on od.orderid = o.orderid group lastname, firstname order 'total sales' desc go
..unless wanted return table output parameter?
(removed use, missed that.. using db..table format)
Comments
Post a Comment