Solved

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

Posted on 2009-05-19
3
982 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

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…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

726 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