Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Start date End date Range from SSRS Parameters against SQL Server 2005

Posted on 2009-05-19
3
Medium Priority
?
985 Views
Last Modified: 2012-05-07
Im tryin to calculate a date range given two calendar input boxes for start and end date;
these paramateres are defined as datetime; as well as datetime in the stored procedure;
However, in the table all of the fields are defined as varchar(50): in the format YYYYMMDD
What is the easiest way I can code this date range for my where clause in which I pass these two mandatory fields to my stored procedure?

I have tried numerous cast and conversion functions but I get an out of bound error when taking in both parameters.  Which is the cleanest way to code this for my where clause?

Thanks
John
@startdate varchar(50)
@enddate varchar(50)

Open in new window

0
Comment
Question by:jtrapat1
3 Comments
 
LVL 27

Accepted Solution

by:
Chris Luttrell earned 2000 total points
ID: 24427913
If you cannot do SELECT convert(datetime,yourDBVarcharField) where you think all the values are in the format 'YYYYMMDD' then you have some invalid dates in there which is what is causing the out of bound error.  It usually is something like '00000000' or '19000000' that is used as a place holder insted of Nulls.  You will have to exclude those dates or do some kind of CASE conversion on them.
0
 
LVL 3

Expert Comment

by:mfreuden
ID: 24427936
Use Datetime for the stored proc parameters, then convert them to varchar inside the proc.  Then you can use the SSRS date field with calendar control.

for example:

sp_testreport @StartdateD datetime,@EndDateD datetime as

declare @StarrtDate varchar(10), @EndDate varchar(10)

select @StartDate=convert(varchar(4),year(@StartDateD))+
                               right('0'+convert(varchar(2),month(@StartDateD)),2)+
                               right('0'+convert(varchar(2),day(@StartDateD)),2)

select @EndDate=convert(varchar(4),year(@EndDateD ))+
                               right('0'+convert(varchar(2),month(@EndDateD )),2)+
                               right('0'+convert(varchar(2),day(@EndDateD )),2)


select * from Table where Datefield between @StartDate and @EndDate







0
 

Author Comment

by:jtrapat1
ID: 24436023
CGLuttrell:

You were absolutely right-
I had blanks in the fields for my dates -
And default values of 19000101.

I thought I had tested for NULLs, spaces, etc....

Thanks Again.
John
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

926 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