I've been having trouble with something i cannot quite get my head around and I was wondering if you can help?
On my table, i have a column called
ADDEDDATE
This column shows the date in which an incident or ticket was added to the database table and its formatting is shown as the following example:
2015-08-25 09:58:14.967
I want to convert this to UNIX timestamp so first i have performed the following:
SELECT DATEDIFF(SECOND,{d '1970-01-01'}, ADDEDDATE) AS 'UNIX DATE ADDED' FROM dbo.TABLE
Running this I get integer values such as "1147855575". Now I understand in order to make this work on UNIX timestamp i need to use BIGINT to convert, so i wrote the following:
SELECT DATEDIFF(SECOND,{d '1970-01-01'}, ADDEDDATE) AS 'UNIX DATE ADDED',
CASE CAST(SUM('UNIX DATE ADDED' AS BIGINT) FROM dbo.TABLE
This returned an error:
Msg 195, Level 15, State 10, Line 2 'SUM' is not a recognized built-in function name.
So i did some googling and searching through Stackoverflow and found i did the second line wrong, it should look like:
SELECT DATEDIFF(SECOND,{d '1970-01-01'}, ADDEDDATE) AS 'UNIX DATE ADDED',
CASE CAST(BIGINT,'UNIX DATE ADDED') FROM dbo.TABLE
However this too fails with the following message:
Msg 1035, Level 15, State 10, Line 2 Incorrect syntax near 'CAST', expected 'AS'.
Can someone please assist me in trying to convert an entire column of integer data to BIGINT for UNIX Datestamp? I am using MSSQL (SSMS 2014).