简体   繁体   中英

How can stored procedure return no rows when called from BIDS but return rows when called from SSMS when using the same parameter?

Using SSRS 2008R2 with a SQL Server 2005 database for the Data Source.

I have a report (.rdl file) built in Business Intelligence Development Studio (VS 2008). It uses a stored procedure as the source of the data. The proc takes one parameter, an INT which is a unique key for the main table in the one SELECT in the proc.

For some parameter values, executing the proc from within the Query Designer of BIDS returns no rows. Executing the same procedure from SSMS using the same parameter value does return rows. Profiler shows the same SELECT regardless of whether the call is made from BIDS or SSMS. How could they get different results?

Here is the proc:

CREATE PROCEDURE [Report_BatchEdit]
    @BatchAltId INT
AS
   SELECT   b.[BatchAltId]
            , fs.[Name] AS [FundingSource]
            , b.[StartDate] AS [StartDate]
            , b.[StopDate] AS [StopDate]
            , b.[Description]
            , b.[Created]
            , bl.[BillId]
            , COALESCE(c.[Name], bill.RecipientCustomerName) AS [CustomerName]
            , COALESCE(ri.[Identifier], bill.[RecipientIdentifier]) AS [MedicaidNumber]
            , bill.[NetTotal] AS [ClaimAmount]
            , bl.[BillingCodeCode] AS [BillingCode]
            , bl.[BillingCodeDescription] AS [BillingCodeDescription]
            , bl.[StartDate] AS [FromDate]
            , bl.[StopDate] AS [ToDate]
            , bl.[UnitSizeName] AS [UnitSize]
            , bl.[CalculatedUnits] AS [Units]
            , bl.[Rate]
            , bl.[Amount]
            , fs.UsesModifiers
            , CASE WHEN fs.UsesModifiers = 1 THEN rm1.[Code] ELSE NULL END AS [RateModifier1Code]
            , CASE WHEN fs.UsesModifiers = 1 THEN rm2.[Code] ELSE NULL END AS [RateModifier2Code]
            , CASE WHEN fs.UsesModifiers = 1 THEN rm3.[Code] ELSE NULL END AS [RateModifier3Code]
            , CASE WHEN fs.UsesModifiers = 1 THEN rm4.[Code] ELSE NULL END AS [RateModifier4Code]
    FROM    [Batch] AS b 
            JOIN [Bill] AS bill ON b.[BatchId] = bill.[BatchId] 
            JOIN [BillLine] AS bl ON bill.[BillId] = bl.[BillId]
            JOIN [Customer] AS fs ON b.[PayerCustomerId] = fs.[CustomerId]
            LEFT JOIN [Customer] AS c ON bill.[RecipientCustomerId] = c.[CustomerId]
            LEFT JOIN [RecipientIdentifier] AS ri ON b.[PayerCustomerId] = ri.[PayerCustomerId] AND bill.[RecipientCustomerId] = ri.[RecipientCustomerId]
            LEFT JOIN [RateModifier] AS rm1 ON bl.[RateModifier1Id] = rm1.[RateModifierId]
            LEFT JOIN [RateModifier] AS rm2 ON bl.[RateModifier2Id] = rm1.[RateModifierId]
            LEFT JOIN [RateModifier] AS rm3 ON bl.[RateModifier3Id] = rm1.[RateModifierId]
            LEFT JOIN [RateModifier] AS rm4 ON bl.[RateModifier4Id] = rm1.[RateModifierId]
   WHERE    BatchAltId = @BatchAltId 
ORDER BY    [FundingSource], b.[StartDate], b.[Description], [CustomerName], [BillingCode], [FromDate], [ToDate]

It sounds silly thing but are you sure the BIDS package is referencing the database on the same server as where SSMS query is running? When I've had things like this happen, I've almost always found an error in the cofiguration of the package and the datasource was pointing to the wrong server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM