Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL DATE convert

Author  Topic 

gooogle
Starting Member

2 Posts

Posted - 2012-08-16 : 15:49:02
I have this SQL below:

.....
where UpdateDateTime > (select CAST ('#p_MaxDate#' as DATETIME))

The value for p_MaxDate that I am getting as parameter is:
p_MaxDate = "2012-08-14 14:15:41"

But I am getting this error:
[Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting date and/or time from character string.

I also tried

where UpdateDateTime >(select CONVERT(DATETIME, ('#p_MaxDate#', 111)) & tried
where UpdateDateTime >(select CAST ('#p_MaxDate#' as DATETIME))

Still same error ...

Any ideas anyone?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-16 : 16:00:44
where are you using this code?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-08-16 : 16:01:23
all between single quotes is a string and the string #p_Maxdate# can't be converted to a date.

what is the real column name? is it p_MaxDate or is it #p_Maxdate# or ...?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

gooogle
Starting Member

2 Posts

Posted - 2012-08-16 : 16:58:26
I am using this inside DataStage SQL stage.

The column name on the table is UpdateDateTime & (p_MaxDate) is the parameter which is being passed in the WHERE clause.

The parameter is being passed as a string & I think I need to convert this from string to datetime or timestamp.
Go to Top of Page
   

- Advertisement -