Solved

SSRS Parameter in Query

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
How to increase the row limit in Jasper Server.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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