Solved

Using Delphi to get the MS SQL Server 2005 database timestamp

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

19 Experts available now in Live!

Get 1:1 Help Now