Link to home
Start Free TrialLog in
Avatar of cerebrumconsulting
cerebrumconsulting

asked on

Using Delphi to get the MS SQL Server 2005 database timestamp

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
Avatar of tigin44
tigin44
Flag of Türkiye image

you can use adocommand, adoquery or adostoredprocedure
Avatar of cerebrumconsulting
cerebrumconsulting

ASKER

I tried the TADOQuery with "SELECT @@DBTS" but got no value back
ASKER CERTIFIED SOLUTION
Avatar of tigin44
tigin44
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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;