datetime conversion in ODBC

Posted by Admin on 02-Mar-2009 16:21

I have a table with a datetime field (ie: 200902031052). I want to write a SQL statement to return just the date portion. I can find how to do that in Progress. I would like something to be returned as 02/03/2009

Select date_time

from tableA

Thanks

All Replies

Posted by Admin on 06-Apr-2009 16:12

Maybe too late, but if someone else comes by with a similar issue:

According to my handy-dandy O'Reilly SQL Pocket Guide:

Select Convert(varchar(10), date_time, 101) AS [date_time] from tableA


where 101 is a style reference to meet your  mm/dd/YYYY requirement

for more style codes try googling  'SQL convert styles' or Microsoft's MSDN: http://msdn.microsoft.com/en-us/library/ms187928.aspx

Posted by kevin_saunders on 07-Apr-2009 01:25

jonas.english wrote:

Maybe too late, but if someone else comes by with a similar issue:

According to my handy-dandy O'Reilly SQL Pocket Guide:

Select Convert(varchar(10), date_time, 101) AS [date_time] from tableA


where 101 is a style reference to meet your  mm/dd/YYYY requirement

for more style codes try googling  'SQL convert styles' or Microsoft's MSDN: http://msdn.microsoft.com/en-us/library/ms187928.aspx

Assuming, of course, that Progress/OpenEdge supports the use of 'SQL convert styles', which I suspect is unlikely, considering the link you posted is titled: "CAST and CONVERT (Transact-SQL)"

Posted by Admin on 07-Apr-2009 06:27

Does it follow the cast of over width database fields into a known size ... or do you till need to adjust the sql width of the column itself?

Wanted to do this in the past, rather than adjust the sql width property (which you may not always be able to do) you "should" be able to cast a string (r subset of) into a derived column of a cast'ed width.

Posted by Admin on 07-Apr-2009 11:47

select top 1 convert(sql_varchar, col1, '101') as col1 from table1   does work with the 10.1c - 5.30.00.74 ODBC driver version.

However after trying out different convert styles (4 or 5 different ones) from the MSDN list (which is why I posted the Cast and Convert MSDN link) the driver ignores the convert style and only returns mm/dd/YYYY

Refer to OpenEdge Data Management: SQL Reference, version 10.1C page 102 specifies the datatypes available for the Convert function.


This thread is closed