Sunday, February 19, 2012

How to use a stored procedure with parameter variables in SSRS

This might be a really dumb question, however I'm having trouble getting this to work.

I created a stored proedure that takes two date variables as such

USE [PdAurius_MonthEnd]
GO
/****** Object: StoredProcedure [dbo].[spBacsTrans] Script Date: 09/13/2006 09:19:24 ******/
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE SPECIFIC_NAME = N'spBacsTrans')
DROP PROCEDURE spBacsTrans

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[spBacsTrans]
@.startdate DATETIME,
@.enddate DATETIME

AS

SELECT
txns.trandate,
ac.accno,
nonpers.name,
txns.bookamt,
txns.txnclrcode as 'clrcode',
right(txns.txncode,2) as FeeType,
left(txns.txncode,4) as TxnType,
txns.empl,
txns.desc1
FROM
txns ,
acct ac,
relate r,
nonpers
WHERE
ac.rowid = txns.FK_rowid_acct
AND ac.rowid = r.FK_rowid_acct
AND nonpers.rowid = r.FK_rowid_nonpers
AND txns.trandate BETWEEN @.startdate AND @.enddate
AND (left(txns.txncode,4) = 'bcom'
AND right(txns.txncode,2) IN(
'01',
'02',
'03',
'04',
'05'))
GROUP BY
right(txns.txncode,2),
txns.trandate,
ac.accno,
nonpers.name,
txns.txnclrcode,
left(txns.txncode,4),
txns.bookamt,
txns.empl,
txns.desc1

OK, so now i created a report & added a dataset (lets call it dataset1).

In the query pane I just wrote spBacsTrans

But it says "could not generate a list of fields for the query" Am I missing a step? I have already added some report parameter.

I even tried writing spBacsTrans @.startdate, @.enddate in the query pane & setting the param values to =Parameters!startdate.value etc but it still not working.

Probably something a bit stupid but then I can be that :)

I thought i was following this post by John Papa but it appears i failed ;)

bump...

any ideas folks?

|||Have you changed the command type of the query from Text to Stored Procedure?|||

Ha Ha LOL

How stupid do I feel now!

Cheers mate.

Actually, In the meantime I also managed to sort out my datepicker issue (reverting to US dates instead of UK) by installing SP1 - so it wasn't time wasted :)

No comments:

Post a Comment