SQL Server Reporting Services Query COMPLETE WHERE CLAUSE PARAMETER?

Hi,

Is it possible for me to pass the where clause to the Sql server report (dataset)?

Select * from where FromDate =@FromDate and ToDate =@ToDate AND strWhere


dkim18Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

planoczCommented:
you have to create vars in your SQL to hold the incoming parameters of the report to fill in the where query in your SQL statement.
dkim18Author Commented:
How can I do that in the SSRS report?
Can you explain?
eiramarCommented:
I hope I understood correctly and you want to pass a dynamic where clause from your report to the dataset. If so, use the firts query, if not maybe the last, more simple, query will work.

Note: the first query uses dynamic sql wich does have a lot of security issues. Please keep that in mind if you are going to use it.

If both don't feed your needs, please explain your problem in more detail.


--query to pass dynamic where clause
CREATE PROCEDURE NewProc
	@FromDate datetime,
	@ToDate datetime,
	@strWhere varchar(max)
AS
DECLARE @Sql varchar(max)

SET @Sql = 'SELECT *
			FROM MyTbl
			WHERE Fromdate = @FromDate 
			AND ToDate = @ToDate
			AND' + @strWhere
			
EXEC @Sql

--more simple query
CREATE PROCEDURE NewProc
	@FromDate datetime,
	@ToDate datetime,
	@strWhere varchar(max)
AS
SELECT *
FROM MyTbl
WHERE Fromdate = @FromDate 
AND ToDate = @ToDate
AND MyColumn = @strWhere

Open in new window

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
eiramarCommented:
Addition to my previous comment. Both queries create a stored procedure. You can use the procedure in a dataset en the variables before the AS part of the query will turn up as paramaters in SSRS.
dkim18Author Commented:
Thanks everyone.

planocz's comment kicked me where to look.

eiramar,

That's exactly what I did.
Thanks again.
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
SSRS

From novice to tech pro — start learning today.