Solved

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

Posted on 2009-05-19
3
972 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 26

Accepted Solution

by:
Chris Luttrell earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

18 Experts available now in Live!

Get 1:1 Help Now