Need help doing SET @StartTime = SELECT GETDATE()

  • Hi experts,

    I retrieve data remotely through a linked server and i want to get the time it takes. This is what I thought I would use:

    DECLARE @MyMessage VARCHAR(100)

    DECLARE @StartTime VARCHAR(25)

    DECLARE @StopTime VARCHAR(25)

    SET @StartTime = SELECT GETDATE()

    ....retrieve data from my linked server...

    SET @StopTime = SELECT GETDATE()

    SET @MyMessage = 'Retrieve time: ' + DATEDIFF(mi, @StartTime, @StopTime)

    This just doesn't work. QueryAnalyzer tells me there is "Incorrect syntax near the keyword 'SELECT'." SELECT GETDATE() works fine on its own. What do I have to do different?

    Thank you and

    Warm regards,

  • Try SELECT @StartTime = GETDATE(). You should declare @StartTime and @StopTime as datetime rather than varchar.

    John

  • Thank you John. It's working great.

    Warm regards,

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply