Solved

SSRS Parameter in Query

Posted on 2008-10-21
4
494 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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