Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

convert string to date format - response (11) by Qaisar Aftab Kiani

$
0
0
SELECT '8/12/2012' AS COL1 , CAST(CASE WHEN CHAR_LENGTH(SUBSTRING(COL1 FROM 1 FOR POSITION('/' IN COL1)-1))=1 THEN '0'||SUBSTRING(COL1 FROM 1 FOR POSITION('/' IN COL1)-1) ELSE SUBSTRING(COL1 FROM 1 FOR POSITION('/' IN COL1)-1) END || '/' || CASE WHEN CHAR_LENGTH(SUBSTRING(SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)) FROM 1 FOR POSITION('/' IN SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)))-1))=1 THEN '0'||SUBSTRING(SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)) FROM 1 FOR POSITION('/' IN SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)))-1) ELSE SUBSTRING(SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)) FROM 1 FOR POSITION('/' IN SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)))-1) END || '/' || SUBSTRING(SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)) FROM POSITION('/' IN SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)))+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN SUBSTRING(COL1 FROM POSITION('/' IN COL1)+1 FOR CHAR_LENGTH(COL1)-POSITION('/' IN COL1)))) AS DATE FORMAT 'DD-MM-YYYY')

Viewing all articles
Browse latest Browse all 27759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>