Solved

SSRS Parameter in Query

Posted on 2008-10-21
4
489 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
  • 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 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now