我正在使用SQL Server 2008 R2,我試圖運行一個查詢,其中存儲過程也將被執行。在選擇查詢中執行存儲過程
查詢是:
select a.custnmbr, a.custname, a.salsterr, b.itemnmbr, b.itemdesc, d.slprsnid ,exec dbo.QtySoldPerMonth a.custnmbr, b.itemnmbr, @year
from rm00101_temp a, iv00101_temp b
inner join sop30300_RPT c on b.itemnmbr = c.itemnmbr
inner join sop30200_RPT d on c.sopnumbe = d.sopnumbe
where
b.itemnmbr like @houseCode + '%' and itmclscd like @classCode + '%'
AND DATEPART(year, d.docdate) = @year
group by a.custnmbr, a.custname, a.salsterr, b.itemnmbr, b.itemdesc, d.slprsnid
order by d.slprsnid, b.itemnmbr
什麼我真的問的是我怎麼去,包括在選擇查詢的dbo.QtySoldPerMonth
存儲過程的執行?此外,存儲過程的參數爲:@custNo = a.custnmbr, @itemNo = b.itemnmbr
和@year = @year
。
任何有關如何重寫查詢執行sp的幫助將不勝感激。
選中此鏈接可能會對您有所幫助。 http://stackoverflow.com/questions/1676655/how-to-query-from-a-stored-procedure-in-sql-server 感謝 – 2013-03-22 16:36:35