Sql server 需要在ssrs报告开始时触发SQL Server存储过程

Sql server 需要在ssrs报告开始时触发SQL Server存储过程,sql-server,tsql,reporting-services,Sql Server,Tsql,Reporting Services,这可能是一个简单的问题,但我需要运行一个报告,以获得触发存储过程的预事件。我不是从该过程返回数据,它是通过从ISAM数据库导出的.csv文件进行大容量插入来更新数据仓库中的2个表。报表本身使用一个单独的查询从SQL Server表中提取数据,但导入的数据最终被多个报表使用,因此需要实际更新这些表 存储过程将作为常规例程的一部分每晚运行,但影响此特定报表的数据将由用户更新,并在运行报表之前立即创建一个新的.csv提取,因此报表需要启动存储过程来更新这些表,然后再查询这些表 我已经尝试过搜索,但我找

这可能是一个简单的问题,但我需要运行一个报告,以获得触发存储过程的预事件。我不是从该过程返回数据,它是通过从ISAM数据库导出的.csv文件进行大容量插入来更新数据仓库中的2个表。报表本身使用一个单独的查询从SQL Server表中提取数据,但导入的数据最终被多个报表使用,因此需要实际更新这些表

存储过程将作为常规例程的一部分每晚运行,但影响此特定报表的数据将由用户更新,并在运行报表之前立即创建一个新的.csv提取,因此报表需要启动存储过程来更新这些表,然后再查询这些表

我已经尝试过搜索,但我找到的所有引用似乎都集中在使用存储过程作为报表查询,而这不是我想要实现的。我有一个用于提取数据的单独查询,如果有意义的话,我需要在报表查询之外和之前运行存储过程

有人知道如何触发存储过程作为报表查询的开始行吗

提前谢谢你的建议。我不是一个SQL程序员或任何类型的程序员,真的,所以请相当具体的与您的建议。。。假设我已有任何知识基础的高级概念可能会在我身上消失

这是我编写的存储过程dbo.KCSI.DataUpdate,如果有帮助的话

--To run as a script (query) the following 2 lines should be un-commented (there are 3 of these 'run-as-a-script' comments to find)
--USE KCSI
--Go

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- To run as a script (query) the following 3 lines should all be commented out
CREATE PROCEDURE DataUpdate
AS
BEGIN

SET NOCOUNT ON 

-- Declare all the needed variables.
DECLARE @CustFile varchar(255)
DECLARE @CustFile_Exists int 
DECLARE @HistFile varchar(255)
DECLARE @HistFile_Exists int
DECLARE @dt varchar(30)
DECLARE @NewCustName varchar(250)
DECLARE @NewHistName varchar(250)

-- Sets Boolean value for whether or not each file exists, using T-SQL extended (i.e. DOS Shell) command
SELECT @CustFile='C:\transfer\ecallcust.csv' 
EXEC Master.dbo.xp_fileexist @CustFile, @CustFile_Exists OUT

SELECT @HistFile='C:\transfer\ecallhist.csv' 
EXEC Master.dbo.xp_fileexist @HistFile, @HistFile_Exists OUT

-- Sets a date variable to append to the final file name
SELECT @dt = REPLACE(Convert(varchar(30),getdate(),120),':','_')
-- Sets a variable to hold the final name. Variable use required because of the hybrid nature of the name (dos shell command + SQL variable)
SET @NewCustName = 'RENAME C:\transfer\history\ecallcust2.csv "ecallcust_'+@dt+'.csv"'
SET @NewHistName = 'RENAME C:\transfer\history\ecallhist2.csv "ecallhist_'+@dt+'.csv"'

-- Subroutine runs only if ecallcust.csv is present
IF @CustFile_Exists = 1
BEGIN

--Zaps the table
TRUNCATE TABLE custextract
-- Initially renames the file, using T-SQL extended (i.e. DOS Shell) command
EXEC master.dbo.xp_cmdshell 'RENAME C:\transfer\ecallcust.csv ecallcust2.csv'

-- Update table from CSV file
BULK INSERT custextract
FROM 'c:\transfer\ecallcust2.csv'
WITH (
ROWTERMINATOR='\n'
)

-- Move file to the history directory and rename it to include the date-time stamp using T-SQL extended (i.e. DOS Shell) command
EXEC master.dbo.xp_cmdshell 'MOVE C:\transfer\ecallcust2.csv C:\transfer\history\'
EXEC master.dbo.xp_cmdshell @NewCustName

END

-- Subroutine runs only if ecallhist.csv is present
IF @HistFile_Exists = 1
BEGIN

--Zaps the table
TRUNCATE TABLE histextract
-- Initially renames the file, using T-SQL extended (i.e. DOS Shell) command
EXEC master.dbo.xp_cmdshell 'RENAME C:\transfer\ecallhist.csv ecallhist2.csv'

-- Update table from CSV file
BULK INSERT histextract
FROM 'c:\transfer\ecallhist2.csv'
WITH (
ROWTERMINATOR='\n'
)

-- Move file to the history directory and rename it to include the date-time stamp using T-SQL extended (i.e. DOS Shell) command
EXEC master.dbo.xp_cmdshell 'MOVE C:\transfer\ecallhist2.csv C:\transfer\history\'
EXEC master.dbo.xp_cmdshell @NewHistName

END

-- To run as a script (query) the following line should be commented out
END
GO
和报告查询

WITH OrderedYTD AS
(
SELECT custextract.*, histextract.*,
       ROW_NUMBER () OVER (PARTITION BY custextract.custcustno ORDER BY histextract.salesytd desc) AS RowNumber
FROM custextract 
INNER JOIN histextract 
    ON custextract.custcustno = histextract.histcustno
WHERE (custextract.ecall = 'Y')
) 

SELECT OrderedYTD.*
FROM OrderedYTD
WHERE RowNumber <= 10;

创建一个存储过程,该存储过程首先更新数据,然后返回要由报表加载的刷新数据

CREATE PROCEDURE DataSelect
AS
BEGIN

    -- Refresh Data Here
    EXEC DataUpdate

    -- Select Data for Report
    WITH OrderedYTD AS
    (
        SELECT custextract.*, histextract.*,
   ROW_NUMBER () OVER (PARTITION BY custextract.custcustno ORDER BY histextract.salesytd desc) AS RowNumber
        FROM custextract 
        INNER JOIN histextract 
            ON custextract.custcustno = histextract.histcustno
        WHERE (custextract.ecall = 'Y')
    ) 

    SELECT OrderedYTD.*
    FROM OrderedYTD
    WHERE RowNumber <= 10;

END

杰出的那么,我可以将报表更改为只使用存储过程而不是它现在使用的查询吗?这会迫使我重新创建报告吗?很抱歉问了这么多问题,但我通常是一名网络技术人员,突然被迫从事设计师的工作。在这之后,我仍然需要弄清楚如何修改它,以接受从网页提供的输入参数,以便按存储进行过滤,并将完成的报告以动态.pdf格式返回,而不是存储在他们浏览器中弹出的磁盘上,以便他们可以在本地打印。到目前为止,我已经连续6天不安了……是的,您必须更改报告以调用sp而不是select,但只要新sp返回与旧select相同的列,您就不必做更多更改。。。其他的ITEN也应该很容易实现,但如果你被卡住了,那就再提出一个问题……:谢谢非常简洁易懂的答案。我真的很感谢你的帮助!