Tuesday, March 27, 2012

DataTime for linked Server

DataTime for linked Server

I have a SQL server in Country A (Server A) and another Server in Country B (Server B) Server A has Server B as linked server, I run a stored procedure in Server A and getdate()gives me current date/time for Server A, how can I do getdate() for Server B?

Hi Jim.H.

You should be able to do this with openquery - try this:

SELECT

*

FROM

OPENQUERY(yourLinkedServer,'SELECT getdate()')

|||

If you're on sql2k5, you can also do this.

Code Snippet

exec ('select getdate() as [date]') AT linked_server_B