Solved

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

Posted on 2009-05-19
3
983 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 27

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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