Showing posts with label starttime. Show all posts
Showing posts with label starttime. Show all posts

Sunday, February 12, 2012

Can't use integer parameter with dateadd?

Hey guys I have the following in my SQL statement:

DATEADD(hh, @.hours, @.startTime)

hours is an integer and startTime is actually a string, but the thing is that this statement works fine if I use it like this:

DATEADD(hh, 8, @.startTime)

The first version is what I need so that the user can control from a parameter and I get the following error:


Error Source: System.Data
Error Message: Failed to convert parameter value from a Decimal to a DateTime.

Thanks!

BJ

have you tried to convert the variable?

Code Snippet

DATEADD(hh, convert(int,(@.hours)), @.startTime)

Simone

Can't use integer parameter with dateadd?

Hey guys I have the following in my SQL statement:
DATEADD(hh, @.hours, @.startTime)
hours is an integer and startTime is actually a string, but the thing is
that this statement works fine if I use it like this:
DATEADD(hh, 8, @.startTime)
The first version is what I need so that the user can control from a
parameter and I get the following error:
Error Source: System.Data
Error Message: Failed to convert parameter value from a Decimal to a DateTime.
Thanks!
BJOn May 11, 1:50 pm, bjkaledas <bjkale...@.discussions.microsoft.com>
wrote:
> Hey guys I have the following in my SQL statement:
> DATEADD(hh, @.hours, @.startTime)
> hours is an integer and startTime is actually a string, but the thing is
> that this statement works fine if I use it like this:
> DATEADD(hh, 8, @.startTime)
> The first version is what I need so that the user can control from a
> parameter and I get the following error:
> Error Source: System.Data
> Error Message: Failed to convert parameter value from a Decimal to a DateTime.
> Thanks!
> BJ
You might need to do something like this:
DATEADD(hh, @.hours, CAST(@.startTime AS DATETIME))
- or- something like this in the report:
=Dateadd("h", Parameters!Hours.Value, CDate(Fields!startTime.Value))
Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant