Solved

Using Delphi to get the MS SQL Server 2005 database timestamp

Posted on 2011-03-14
4
1,054 Views
Last Modified: 2012-05-11
I need to retrieve the database timestamp from an MS SQL Server 2005 database.  The Transact SQL method is "SELECT @@DBTS".

How can I do this using a Delphi component?  Do I use a TADOStoredProc? If so, what it the procedure name?

Thanks,

Eric
0
Comment
Question by:cerebrumconsulting
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 35133427
you can use adocommand, adoquery or adostoredprocedure
0
 

Author Comment

by:cerebrumconsulting
ID: 35133456
I tried the TADOQuery with "SELECT @@DBTS" but got no value back
0
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 35133478
use an alias for the field name and reference this while getting the value...


"SELECT @@DBTS as mydate"
0
 

Author Comment

by:cerebrumconsulting
ID: 35134064
Thanks, that was a help.  My problem was deeper, but I didn't know that when i wrote the question.

This is the final solution.  I had to declare the @@DBTS variable as a field (LastUpdate) as you suggested.

// Temp is the TADOQuery component
Unit Math;

var
  OrigValue :TBytes;
  Int64Representation :Int64;
begin
  Temp.Open;
  setlength(OrigValue, length(TempLastUpdate.AsBytes));
  OrigValue := TempLastUpdate.AsVariant; // .AsBytes gave a type mismatch even though both are declared as TBytes ???

   Int64Representation := OrigValue[0]
      + (OrigValue[1]*Round(IntPower(256, 1)))
      + (OrigValue[2]*Round(IntPower(256, 2)))
      + (OrigValue[3]*Round(IntPower(256, 3)))
      + (OrigValue[4]*Round(IntPower(256, 4)))
      + (OrigValue[5]*Round(IntPower(256, 5)))
      + (OrigValue[6]*Round(IntPower(256, 6)))
      + (OrigValue[7]*Round(IntPower(256, 7)));
   Caption := IntToStr(Int64Representation); // Show that we have actually retrieved a readable number
   Temp.Close;
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

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now