最終的に毎日の財務情報を取得する3つのクエリがあります。私がやりたいのは、必要な列を1つの入力として結合することです。派生テーブルを試してみましたが、非常にずさんで機能しませんでした。これら3つを組み合わせて1行で出力する方法について誰かが提案を持っていますか?
これが私の質問です:
SELECT ReportCategoryID, ReportCategoryName, PrintOrder, QTY, NetAmt, customers, Average
FROM dbo.fRevenueSummary(@startdate, @enddate) AS fRevenueSummary_1
2番目のクエリ:
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'))
3番目のクエリ:
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')