Solved

Convert timestamp to long or double.

Posted on 2009-04-06
4
1,258 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 500 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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

679 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