我有,我想用它来创建我的应用程序(C#)报表中的SQL Server存储过程。
因为在过程中的表是动态创建的,我用它来创建报告有问题。
如何使用此过程创建我的应用程序的报告?
我使用VS2010,SQL Server 2008 R2的
我在VS创建数据,但不知道如何从那里使用它。 报告向导不能使用我创建的数据集。
我给想以某种方式使用此创建一个视图,然后生成从该数据集,但不能找出答案。
我希望我已经提供了有人给我一些指导足够的信息。
PROCEDURE sp_RD_Reporting_View_ExportedData_For_Period
(
@StartDate date,
@EndDate date
)
AS
CREATE TABLE #tmp
(
StartDate DATETIME,
EndDate DATETIME,
FomatedDate VARCHAR(20)
)
--Calculate the date ranges
;WITH Nbrs ( n ) AS (
SELECT 0 UNION ALL
SELECT 1+n FROM Nbrs WHERE n < 6 )
INSERT INTO #tmp
SELECT
DATEADD(DAY,-n,@StartDate),
DATEADD(DAY,-n,@EndDate),
convert(varchar, DATEADD(DAY,-n,@EndDate), 110)
FROM
Nbrs
ORDER BY
-n
--The date columns for the pivot
DECLARE @cols VARCHAR(MAX)
SELECT @cols = COALESCE(@cols + ','+QUOTENAME(FomatedDate),
QUOTENAME(FomatedDate))
FROM
#tmp
--Declaring some dynamic sql and executing it
DECLARE @query NVARCHAR(4000)=
N'SELECT
*
FROM
(
SELECT ExportData.EmployeeID AS EmpID,
ABRAempInfo.EmpFullName AS Name,
ExportData.PayType AS PayType,
tmp.FomatedDate,
SUM(ExportData.Quantity) AS Hours
FROM ExportData
JOIN ABRAempInfo
ON ExportData.EmployeeID = ABRAempInfo.EmpID
JOIN #tmp AS tmp
ON ExportData.ChargeDate = tmp.FomatedDate
WHERE ChargeDate BETWEEN tmp.StartDate AND tmp.EndDate
GROUP BY ExportData.EmployeeID, ExportData.PayType, tmp.FomatedDate, ABRAempInfo.EmpFullName
) AS p
PIVOT
(
SUM(Hours)
FOR FomatedDate IN ('+@cols+')
) AS pvt'
EXECUTE(@query)
DROP TABLE #tmp