Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert date to character 'YYYYMM' with substring and extract function 1

Status
Not open for further replies.

titio

Programmer
Mar 27, 2001
2
FR
What is the correct sql syntax for retreiving a character month column like 'YYYYMM' from a date ?

i try this but no success

SUBSTRING ( EXTRACT YEAR from date || EXTRACT MONTH from date 1 for 6 ) ????????????
 
Try this:-

select trim(extract(year from date))||trim(extract(month from date) (format '99'));
 
or alternatively from BTEQ/ODBC:

Code:
select 
  data1,
  data2,
  cast((datefield (format 'YYYYMM')) as char(6)) as YearMonth
from
  sourcetbl;

Note: The cast to char(6) is only required if you are retrieving data via ODBC (if omitted it just comes across as the date field unchanged since it is converted into ODBC datatypes and the format is ignored)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top