Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Splitting one column into different columns.

$
0
0

Hello Experts,

How do i split datetime column into different columns while doing a Select statement.

Ex:

The column "REC_CRT_TS" has data like "2014-05-08 08:23:09.0000000".The datatype of this column is "DateTime". And i want it in SELECT statement like;

SELECT 
YEAR(DATETIME) YEAR, 
MONTH(DATETIME) MONTH, 
DATENAME(DATETIME) MONTHNAME, 
DATEPART(DATETIME) WEEKNUM, 
DAY(DATETIME) DATE, 
DATEPART(DATETIME) HOUR
FROM TABLE_NAME;

The output should look like this;

--YEAR| MONTH | MONTHNAME| WEEKNUM | DATE | HOUR
--2014| 5     | May     | 25       | 08    |08

Any suggestions please.

Thanks!


Rahman


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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