Using SSMS, the code below works perfectly fine. When I input the code into a Dataset in SSRS, the report data view doesn't show any of the fields the exec() function outputs. I use these fields in other areas of the report to filter and sort by, so the report is currently broken. I have looked into other questions on here, and they don't address this situation. If there is a way to store this query as a stored procedure and then call it in SSRS, that will work for me. I just don't know how to do that.
Declare @YR2 VARCHAR(MAX), @YR1 VARCHAR(MAX)
Declare @MT2 VARCHAR(MAX), @MT1 VARCHAR(MAX)
Declare @Query VARCHAR(MAX)
SET @YR2 = YEAR(dateadd(month, datediff(month, 0, getdate())-2, 0))
SET @YR1 = YEAR(dateadd(month, datediff(month, 0, getdate())-1, 0))
SET @MT2 = FORMAT(MONTH(dateadd(month, datediff(month, 0, getdate())-2, 0)),'00')
SET @MT1 = FORMAT(MONTH(dateadd(month, datediff(month, 0, getdate())-1, 0)),'00')
Set @Query = 'Select * FROM
(Select '+@MT2+'.'+@YR2+' as [Starting Point],ACCT_NBR as [Account],NBR_DUE From dbo.EOM_DB99_CalculatedValues_'
+ @YR2 + @MT2 + ' UNION ALL
Select '+@MT1+'.'+@YR1+' as [Starting Point],ACCT_NBR as [Account],NBR_DUE From dbo.EOM_DB99_CalculatedValues_'
+ @YR1 + @MT1 + ') a Where a.Account IN (Accounts)'
Exec(@Query)
I was needing to automate a report that always uses the previous 2 EOM tables from the database and this was the only way I could get it to work in SSMS. Now I just need it to work in Report Builder 2014. I am open to ideas!
output
question from:
https://stackoverflow.com/questions/65649598/report-builder-not-listing-any-fields-from-query-using-execcustomquery-to-out 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…