2014-11-11 4 views
0

테이블 반환 매개 변수가 공백 레코드 집합을 반환하기 전이나 후에 하나 이상의 nullable 매개 변수를 추가해야하는 이유를 이해하는 데 어려움을 겪고 있습니다. http://geekswithblogs.net/GruffCode/archive/2012/06/21/using-table-valued-parameters-with-sql-server-reporting-services.aspx 다음SSRS가 테이블 반환 매개 변수가있는 데이터를 반환하지 않습니다.

내가 내 환경을 모방하기 위해 추가 매개 변수를 추가하고 내가 여기 @ ACCOUNTTYPE = 4

와 @ ACCOUNTTYPE = NULL을 대체하지 않는 한 나는 더 이상 기록을 얻을 수 없습니다

나는 성공적으로 여기에 예를 따라 데이터 세트의 코드입니다 :

exec(' declare @customerIdList Report.IntegerListTableType ' + @customerIdInserts + 
' EXEC rpt_CustomerTransactionSummary 
@startDate=''' + @startDate + ''', 
@endDate=''' + @endDate + ''', 
@customerIds = @customerIdList') 

은이는 SQL 추적 (결과 : 빈 레코드)입니다

exec sp_executesql N'exec('' declare @customerIdList Report.IntegerListTableType '' + @customerIdInserts + 
'' EXEC rpt_CustomerTransactionSummary 
@startDate='''''' + @startDate + '''''', 
@endDate='''''' + @endDate + '''''', 
@accountType='''''' + @accountType + '''''', 
@customerIds = @customerIdList'')', 
N'@customerIdInserts nvarchar(40), 
@startDate datetime, 
@endDate datetime, 
@accountType int', 
@customerIdInserts=N'INSERT @customerIdList VALUES (304813)', 
@startDate='2013-01-01 00:00:00', 
@endDate='2014-12-31 00:00:00', 
@accountType=NULL 

내가 4로 NULL을 교체하고 내가 예상 결과를 얻을 SQL 관리 스튜디오에서 쿼리를 실행하는 경우 :

exec sp_executesql N'exec('' declare @customerIdList Report.IntegerListTableType '' + @customerIdInserts + 
'' EXEC rpt_CustomerTransactionSummary 
@startDate='''''' + @startDate + '''''', 
@endDate='''''' + @endDate + '''''', 
@accountType='''''' + @accountType + '''''', 
@customerIds = @customerIdList'')', 
N'@customerIdInserts nvarchar(40), 
@startDate datetime, 
@endDate datetime, 
@accountType int', 
@customerIdInserts=N'INSERT @customerIdList VALUES (304813)', 
@startDate='2013-01-01 00:00:00', 
@endDate='2014-12-31 00:00:00', 
@accountType=4 

사람이 올바른 방향으로 저를 설정하시기 바랍니다 수 있습니까?

감사

답변

0

저장 프로 시저를 공급 한 후 내 대답을 수정했습니다. 계정 유형이 int 대신 null이기 때문에 0이 될 것이라고 생각합니다. 이 변경

시도 :

AND (accountType= @accountType OR @accountType = 0) 
+0

와우에

exec(' declare @customerIdList Report.IntegerListTableType ' + @customerIdInserts + ' EXEC rpt_CustomerTransactionSummary @startDate=''' + @startDate + ''', @endDate=''' + @endDate + ''', @accountType=''' + @accountType + ''', @customerIds = @customerIdList') 

에서 "텍스트"쿼리 유형

를 고정하여 문제를 해결! 그것은 실제로 효과가있다! – user4241675

+0

이제 실제 시나리오에서 제로 (0)가 실제 값인 값을 가질 수 있는지 테스트해야합니다. 나는 계속 너를 게시 할 것이다. 그동안 대단히 감사합니다 – user4241675

+0

전혀 probs 없습니다. –

0

이 내 저장된 프로 시저 :

ALTER PROCEDURE dbo.rpt_CustomerTransactionSummary 
(
@startDate datetime, 
@endDate datetime, 
@customerIds Report.IntegerListTableType READONLY, 
@accountType int 
) 
AS 
BEGIN 
    SET NOCOUNT ON; 


    SELECT t.PlayerID, t.InsertedDatetime, t.Amount 
    FROM transactions t 
    INNER JOIN @customerIds AS c on t.PlayerID = c.Value 
    WHERE InsertedDatetime BETWEEN @startDate AND @endDate 
    AND (@accountType IS NULL OR [email protected]) 


END 
0

솔루션 그것은 우리가 이미 추한 해킹에 그것을 추가 싫증이 나다했다 그러나 일 로버트. 우리는

DECLARE @vSQL nvarchar(max) = N' 
DECLARE @customerIdList Report.IntegerListTableType; 
'[email protected]+'; 
EXEC rpt_CustomerTransactionSummary 
@[email protected], 
@[email protected], 
@[email protected], 
@customerIds = @customerIdList'; 
exec sp_executesql 
    @vSQL, 
    N'@startDate datetime, @endDate datetime, @accountType int', 
    @startDate, 
    @endDate, 
    @accountType; 
관련 문제