How to change the dataset code in SSRS to a store procedure

Hi Experts,

My manager wants me to use a store procedure instead of dataset code in SSRS. This is the original dataset code in SSRS below. I tried to change it to a store procedure, but the data did not show through the store procedure. Can you help me on it? Thanks.

Set DATEFIRST 1
Declare @BeginDate datetime 
Declare @MyTable table(
	StoreID int
)
IF @AMID is null
BEGIN
	Insert into @MyTable Select StoreID from tblStores
END
ELSE
BEGIN
	Insert into @MyTable Select StoreID from tblStores Where AMID=@AMID
END


Set @BeginDate=DateAdd(d,-DatePart(dw,@EndDate),@EndDate)

SELECT  @BeginDate as BeginDate,@EndDate as ReportDate,  
	tblStores.StoreID, tblStores.StoreName, ContractString,
	UPPER(vps.UserFirstName) + ' ' + UPPER(vps.UserLastName) as VPName,
	UPPER(ams.UserFirstName) + ' ' + UPPER(ams.UserLastName) as AMName,
	tblLoans.LoanID, 
	tblCustomers.CustomerFirstName + ' ' + tblCustomers.CustomerLastName as CustomerName, 
         tblUsers.UserFirstName + ' ' + tblUsers.UserLastName as Employee, 
	tblLoanTransactions.TransactionDateTime,  
         tblLoanTransactions.TransactionAmt, 
	tblLoanTransactions.TransactionNotes, 
	tblLoanTransactions.TransactionID as ReceiptNumber, 
	tblStores.vpID, 
	tblStores.amID,TransactionPrincPaid,TransactionInterPaid,SettlementReason,SettlementAmount
FROM         tblLoanTransactions INNER JOIN
                      tblLoans ON tblLoanTransactions.LoanID = tblLoans.LoanID INNER JOIN
                      tblReportingTransactions ON tblLoanTransactions.TransactionID = tblReportingTransactions.TransactionID INNER JOIN
                      tblStores ON tblLoans.LoanStoreID = tblStores.StoreID INNER JOIN
                      tblUsers ON tblLoanTransactions.TransactionUserID = tblUsers.UserID INNER JOIN
                      tblCustomers ON tblLoans.CustomerID = tblCustomers.CustomerID
			INNER JOIN tblUsers ams
			on tblStores.AMID=ams.UserID

			INNER JOIN tblUsers vps
			on tblStores.VPID=vps.UserID
WHERE              (tblLoanTransactions.TransactionDateTime between @BeginDate and @EndDate+' 23:59:59') and tblLoanTransactions.TransactionTypeID in (9, 10)
 AND tblloans.LoanStoreID  IN (Select StoreID from @MyTable)
AND tblLoanTransactions.TransactionAmt>0
ORDER BY AMName, tblstores.storeid

Open in new window

tanj1035Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tanj1035Author Commented:
Can you help me work on the code of store procedure? Many Thanks!
0
Vadim RappCommented:
Probably
create procedure MyProc (@amid int, @endDate datetime) as -- <--- adjust datatype of parameters
Set DATEFIRST 1
Declare @BeginDate datetime 
Declare @MyTable table(
	StoreID int
)
IF @AMID is null
BEGIN
	Insert into @MyTable Select StoreID from tblStores
END
ELSE
BEGIN
	Insert into @MyTable Select StoreID from tblStores Where AMID=@AMID
END


Set @BeginDate=DateAdd(d,-DatePart(dw,@EndDate),@EndDate)

SELECT  @BeginDate as BeginDate,@EndDate as ReportDate,  
	tblStores.StoreID, tblStores.StoreName, ContractString,
	UPPER(vps.UserFirstName) + ' ' + UPPER(vps.UserLastName) as VPName,
	UPPER(ams.UserFirstName) + ' ' + UPPER(ams.UserLastName) as AMName,
	tblLoans.LoanID, 
	tblCustomers.CustomerFirstName + ' ' + tblCustomers.CustomerLastName as CustomerName, 
         tblUsers.UserFirstName + ' ' + tblUsers.UserLastName as Employee, 
	tblLoanTransactions.TransactionDateTime,  
         tblLoanTransactions.TransactionAmt, 
	tblLoanTransactions.TransactionNotes, 
	tblLoanTransactions.TransactionID as ReceiptNumber, 
	tblStores.vpID, 
	tblStores.amID,TransactionPrincPaid,TransactionInterPaid,SettlementReason,SettlementAmount
FROM         tblLoanTransactions INNER JOIN
                      tblLoans ON tblLoanTransactions.LoanID = tblLoans.LoanID INNER JOIN
                      tblReportingTransactions ON tblLoanTransactions.TransactionID = tblReportingTransactions.TransactionID INNER JOIN
                      tblStores ON tblLoans.LoanStoreID = tblStores.StoreID INNER JOIN
                      tblUsers ON tblLoanTransactions.TransactionUserID = tblUsers.UserID INNER JOIN
                      tblCustomers ON tblLoans.CustomerID = tblCustomers.CustomerID
			INNER JOIN tblUsers ams
			on tblStores.AMID=ams.UserID

			INNER JOIN tblUsers vps
			on tblStores.VPID=vps.UserID
WHERE              (tblLoanTransactions.TransactionDateTime between @BeginDate and @EndDate+' 23:59:59') and tblLoanTransactions.TransactionTypeID in (9, 10)
 AND tblloans.LoanStoreID  IN (Select StoreID from @MyTable)
AND tblLoanTransactions.TransactionAmt>0
ORDER BY AMName, tblstores.storeid

Open in new window


You will have to call this stored procedure with parameters @amid and @enddate.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ValentinoVBI ConsultantCommented:
I've got a couple of articles on that, may be good to have a read through.  Here they are:

Reporting On Data From Stored Procedures (part 1)
Reporting On Data From Stored Procedures (part 2)
1
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kannanpdxCommented:
if the data is not returned from the stored procedure there may be some thing wrong with your joins or data..

try troubleshooting..  you can use print and select statements  on stored procedures to see the expected values are returned.

like make sure you have data on @MyTable .. do select * from @MyTable after the below block of statement in your stored procedure..


"IF @AMID is null
BEGIN
      Insert into @MyTable Select StoreID from tblStores
END
ELSE
BEGIN
      Insert into @MyTable Select StoreID from tblStores Where AMID=@AMID
END"


Take the query from data set and execute by passing the required parameters.. if this is returning records..

create a stored procedure with same query and same parameter..This must match the rows that you are getting on data set.. check on the link provided by ValentinoV ...
1
tanj1035Author Commented:
Thank Valentino and kannanpdx's sharing. I will read the articles.
0
Vadim RappCommented:
little cosmetic improvement: instead of

IF @AMID is null
BEGIN
      Insert into @MyTable Select StoreID from tblStores
END
ELSE
BEGIN
      Insert into @MyTable Select StoreID from tblStores Where AMID=@AMID
END

we can use

Insert into @MyTable Select StoreID from tblStores where AMID=isnull(@AMID,AMID)
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.