Solved

Using Delphi to get the MS SQL Server 2005 database timestamp

Posted on 2011-03-14
4
1,057 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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