我有 3 个查询最终获得了我的日常财务信息。我想做的是将我需要的列组合为 1 个输入。我试着做派生表,但它非常草率而且没有用。有没有人对我如何将这 3 个结合起来在 1 行上给我输出有任何建议?
这是我的查询:
SELECT ReportCategoryID, ReportCategoryName, PrintOrder, QTY, NetAmt, customers, Average
FROM dbo.fRevenueSummary(@startdate, @enddate) AS fRevenueSummary_1
第二个查询:
SELECT COUNT(*) AS count, SUM(TicketsDetails.dblTotal) AS Merch_Total
FROM TicketsDetails INNER JOIN
Surcharges ON TicketsDetails.Reference_ID = Surcharges.Surcharge_ID INNER JOIN
SurchargesTypes ON Surcharges.lSurchargeTypeID = SurchargesTypes.lSurchargeTypeID
WHERE (TicketsDetails.dtCreated BETWEEN @startdate AND @enddate) AND (SurchargesTypes.lSurchargeTypeID = '2') AND (TicketsDetails.bPaid = 1) AND
(TicketsDetails.Detail_Type_ID = 3) AND (NOT (TicketsDetails.sDescription = N'TIP'))
第三个查询:
SELECT SUM(dblRegLabor) AS Regular_Amount, SUM(dblOTLabor) AS OT_Amount
FROM TimeClock
WHERE (dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '1') OR
(dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '2') OR
(dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '3') OR
(dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '4') OR
(dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '5') OR
(dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '6') OR
(dtTimeIn > @startdate) AND (dtTimeOut < @enddate) AND (sDept = '7')