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
How can I do this using a Delphi component? Do I use a TADOStoredProc? If so, what it the procedure name?
Thanks,
Eric
you can use adocommand, adoquery or adostoredprocedure
ASKER
I tried the TADOQuery with "SELECT @@DBTS" but got no value back
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.AsBy tes));
OrigValue := TempLastUpdate.AsVariant; // .AsBytes gave a type mismatch even though both are declared as TBytes ???
Int64Representation := OrigValue[0]
+ (OrigValue[1]*Round(IntPow er(256, 1)))
+ (OrigValue[2]*Round(IntPow er(256, 2)))
+ (OrigValue[3]*Round(IntPow er(256, 3)))
+ (OrigValue[4]*Round(IntPow er(256, 4)))
+ (OrigValue[5]*Round(IntPow er(256, 5)))
+ (OrigValue[6]*Round(IntPow er(256, 6)))
+ (OrigValue[7]*Round(IntPow er(256, 7)));
Caption := IntToStr(Int64Representati on); // Show that we have actually retrieved a readable number
Temp.Close;
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.AsBy
OrigValue := TempLastUpdate.AsVariant; // .AsBytes gave a type mismatch even though both are declared as TBytes ???
Int64Representation := OrigValue[0]
+ (OrigValue[1]*Round(IntPow
+ (OrigValue[2]*Round(IntPow
+ (OrigValue[3]*Round(IntPow
+ (OrigValue[4]*Round(IntPow
+ (OrigValue[5]*Round(IntPow
+ (OrigValue[6]*Round(IntPow
+ (OrigValue[7]*Round(IntPow
Caption := IntToStr(Int64Representati
Temp.Close;