?
Solved

SSRS Parameter in Query

Posted on 2008-10-21
4
Medium Priority
?
498 Views
Last Modified: 2012-05-05
This below query runs GREAT.  But, for reporting purposes, I created a Parmeter in SSRS called "Date" and I can't seem to figure out how to have this SELECT query base its Date values off of the value the user will put in for this parameter.    I thought it would be something like this, but it doesn't seem to work:

SELECT     CHECKMAST.LEVEL1ORG, CHECKMAST.BANKACCTNUM, CHECKMAST.DATEPROCESSED, CHECKMAST.VOIDPOSTDATE, CHECKMAST.CHECKNUM,
                      CHECKMAST.CHECKAMT, CHECKMAST.CHECKDATE, CHECKMAST.STATUS
FROM         AP.CHECKMAST CHECKMAST
WHERE     (CHECKMAST.LEVEL1ORG = 2000) AND (CHECKMAST.BANKACCTNUM = '726252') AND
                      (CHECKMAST.DATEPROCESSED >= (@DATE)) AND (CHECKMAST.DATEPROCESSED < (@DATE)) OR
                      (CHECKMAST.LEVEL1ORG = 2000) AND (CHECKMAST.BANKACCTNUM = '726252') AND (CHECKMAST.VOIDPOSTDATE >= (@DATE))
                       AND (CHECKMAST.VOIDPOSTDATE < (@DATE))
SELECT     CHECKMAST.LEVEL1ORG, CHECKMAST.BANKACCTNUM, CHECKMAST.DATEPROCESSED, CHECKMAST.VOIDPOSTDATE, CHECKMAST.CHECKNUM, 
                      CHECKMAST.CHECKAMT, CHECKMAST.CHECKDATE, CHECKMAST.STATUS
FROM         AP.CHECKMAST CHECKMAST
WHERE     (CHECKMAST.LEVEL1ORG = 2000) AND (CHECKMAST.BANKACCTNUM = '726252') AND 
                      (CHECKMAST.DATEPROCESSED >= { ts '2008-10-17 00:00:00' }) AND (CHECKMAST.DATEPROCESSED < { ts '2008-10-18 00:00:00' }) OR
                      (CHECKMAST.LEVEL1ORG = 2000) AND (CHECKMAST.BANKACCTNUM = '726252') AND (CHECKMAST.VOIDPOSTDATE >= { ts '2008-10-17 00:00:00' })
                       AND (CHECKMAST.VOIDPOSTDATE < { ts '2008-10-18 00:00:00' })

Open in new window

0
Comment
Question by:chrisryhal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:jgv
ID: 22768142
In the crystal code the dates are hardcoded and in each of the ranges there is a one day difference (2008-10-17 to 2008-10-18). Your SQL query is using the same parameter on both sides of the range (ie: 2008-10-17 to 2008-10-17). For this to work like the crystal code you will either need to create another date parameter (ie: EndDate) or you need to add 1 day to the date the user selects.
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 22768217
I was just going to add one day to the date the user selects.

I can't figure out how to tell this SELECT statement though to use the Parameter.  What would it look like?
0
 
LVL 12

Accepted Solution

by:
jgv earned 2000 total points
ID: 22768286
You have the parameter setup in the query properly but the brackets are unnecessary (you only need these when you are using an IN operator). You can use the DateAdd function to add a day to the parameter from within the query. Example:
(CHECKMAST.VOIDPOSTDATE >= @DATE)
                       AND (CHECKMAST.VOIDPOSTDATE < DATEADD(day, 1, @DATE))

0
 
LVL 2

Author Closing Comment

by:chrisryhal
ID: 31508323
Thanks for the help.    Perhaps you may have some insight on this question?  http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_23840892.html
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question