0
我有三個表table1,table2和table3。以下是我的存儲過程。執行存儲過程後,我得到了以下輸出。如何在單個存儲過程中從多個表中獲取數據?
alter PROCEDURE test
@SDate datetime,
@EDate datetime
As
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Select count(quoteid) as TotalQuote, sum(totalamount) as QuoteAmount from dbo.QuoteBase
where CreatedOn BETWEEN @SDate AND @EDate
select count(salesorderid)as TotalOrders, sum(totalamount) as OrderAmount from dbo.SalesOrderBase Where
CreatedOn BETWEEN @SDate AND @EDate
select count(opportunityid)as TotalSales from dbo.OpportunityBase Where
CreatedOn BETWEEN @SDate AND @EDate
GO
輸出
,但我不想單獨顯示查詢結果。
我該怎麼做才能讓查詢結果成爲一行?
使用聯合查詢。 'select ... UNION select ... UNION select ...' –
以下是如何解決您的問題 http://stackoverflow.com/questions/7239450/returning-multiple-tables-from-a-stored -程序 – isxaker