Solved

How can I pass DATETIME type from a report in reporting services to a stored procedure?

Posted on 2008-06-24
10
760 Views
Last Modified: 2013-12-07
I have a reporting services report which has a dataset based on the SQL snippet below.

I have designed the report in reporting services and have set the date parameters to DateTime (so i get the calendar datepicker).  However, I cannot run the report because it says the datetime is formatted incorrectly.

Can anyone help?




@locationID NVARCHAR(15),@fromDate DATETIME,@toDate DATETIME

SELECT *

FROM Statistics

WHERE [Location ID]=@locationID AND DateViewed BETWEEN @fromDate AND @toDate

-- The following query works --

SELECT *

FROM Statistics

WHERE [Location ID]='LOC001' AND DateViewed BETWEEN '20041231' AND '20061231'

Open in new window

0
Comment
Question by:almuallim
  • 5
  • 3
  • 2
10 Comments
 
LVL 14

Expert Comment

by:Jagdish Devaku
Comment Utility
Hi,

Please refer to the following link, which might help you,....

http://msdn.microsoft.com/en-us/library/ms189794.aspx

all the best...
0
 

Author Comment

by:almuallim
Comment Utility
Hiya,

I don't quite understand what you mean.  Datediff will find the difference between two dates; however, i'm having a problem passing datetime value from my report to my stored procedure.   Please clarify.
0
 
LVL 14

Expert Comment

by:Jagdish Devaku
Comment Utility
Sorry for my above post...

I giving you an example on how to retrieve the data betwwen two dates... i think this will work...

Declare @vdate1 varchar(50);
Declare @vdate2 varchar(50);


set @vdate1 = getdate(); --todays date
set @vdate2 = getdate()+100; -- date after 100 days

--Sql statement to compare 2 dates

SELECT * FROM Mytable
WHERE (CONVERT(varchar,DateColumn,style) >= @vdate1 AND
CONVERT(varchar,DateColumn,style) <= @vdate2)
0
 

Author Comment

by:almuallim
Comment Utility
Hi,

I know what you mean.  But I want to use the datepicker in SQL Reporting Services.  That can only be used when the parameter if of type DATETIME.  If i change it to string then the datepicker does not appear (which is bad from a user perspective).

0
 
LVL 5

Expert Comment

by:catherinelouise
Comment Utility
Keep your parameter as a datetime so you have the SQL picker.  I think you then need to use a convert in your code such as:
AND DateViewed BETWEEN CONVERT(CHAR, @fromDate,112) AND  CONVERT(CHAR, @toDate,112)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:almuallim
Comment Utility
Closer...
Now, I have changed my query as per above.  When i test the query in the Data tab of report designer it works fine(with english formatted date).  However, when i prevew the report and try and use the datepicker it says parameter not in correct format.

"The value provided for the report parameter 'fromDate' is not valid for its type"
0
 
LVL 5

Accepted Solution

by:
catherinelouise earned 500 total points
Comment Utility
Do you have SQL 2005 SP1 installed?  Seems like this was a bug that was resolved:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=255248&SiteID=1
0
 

Author Comment

by:almuallim
Comment Utility
Installing it now!  Will let you know how it goes...
0
 
LVL 5

Expert Comment

by:catherinelouise
Comment Utility
Fingers crossed!  If you go the whole way through the thread you'll find there were varying solutions.  If you still have the same problem, check out the thread originators final comment:

Manually edit the ReportViewer.aspx on the server to add Culture="en-GB" to the @page directiveso that the date picker puts the date into the date box the UK way round.

Use the Internet Explorer lanugage settings to put en-GB at the top of the language list on my client machines (I've never neaded to press that button before today).
0
 

Author Closing Comment

by:almuallim
Comment Utility
Worked a treat.  Funny how it's always the simplest of solutions.  Thanks for your help
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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

743 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

11 Experts available now in Live!

Get 1:1 Help Now