Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert timestamp to long or double.

Posted on 2009-04-06
4
Medium Priority
?
1,364 Views
Last Modified: 2012-05-06
How can I cast the resulting timestamp value into a long or double:

    SELECT Max(q.Modified) FROM (
                  SELECT Modified FROM Table1
                        UNION ALL
                  SELECT Modified FROM Table2
                        UNION ALL
                  SELECT Modified FROM Table3
                        UNION ALL
                  SELECT Modified FROM Table4
            ) as q

Modified is defined as type "timestamp" in all tables.

Kevin
0
Comment
Question by:zorvek (Kevin Jones)
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24081911
you mean:
SELECT cast( Max(q.Modified) as double) 
FROM (
                  SELECT Modified FROM Table1
                        UNION ALL
                  SELECT Modified FROM Table2
                        UNION ALL
                  SELECT Modified FROM Table3
                        UNION ALL
                  SELECT Modified FROM Table4
            ) as q

Open in new window

0
 
LVL 6

Expert Comment

by:RPCIT
ID: 24081912
what value do you want in the long or double?  are you looking for some kind of julian value? or something special?
0
 
LVL 15

Accepted Solution

by:
MNelson831 earned 2000 total points
ID: 24081929
Long and Double are not SQL Datatypes.  Try Int or BigInt instead
Have you tried:

SELECT Convert(Int,Max(q.Modified) )
SELECT Convert(BigInt,Max(q.Modified) )
0
 
LVL 81

Author Comment

by:zorvek (Kevin Jones)
ID: 24082137
MNelson831,

You are correct. This worked:

SELECT CAST(MAX(q.Modified) AS BIGINT)
FROM (
                  SELECT Modified FROM Table1
                        UNION ALL
                  SELECT Modified FROM Table2
                        UNION ALL
                  SELECT Modified FROM Table3
                        UNION ALL
                  SELECT Modified FROM Table4
            ) as q

RPCIT - I'm just trying to get timestamp into a numeric form...when I return a timestamp value it is passed to ADODB as an array of 8 bytes.

Guy - Sorry, dude, your next 2,000 points won't come from me this time. Don't you have enough anyway? ;-)

Kevin
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question