Using "USE DB GO" within an OPENQUERY

  • Hi guys,

    retrieving data from some servers I try to use the next syntax

    SELECT * FROM OPENQUERY( [linked server],'SET FMTONLY OFF; EXEC (''DBCC showfilestats WITH NO_INFOMSGS '')')

    but this retrieves the filestats from master only.

    How can I use this syntax going to a specific database.

    --------------

    Or ;

    Why does the syntaxs;

    USE database

    GO

    EXEC ('DBCC showfilestats WITH NO_INFOMSGS ')

    works fine and

    USE database GO EXEC ('DBCC showfilestats WITH NO_INFOMSGS ')

    does not work??

    Who can help me out on this?

    Regards.

    Guus Kramer

    The Netherlands

  • you need to put the Use statement in the Exec call.

    SELECT * FROM OPENQUERY( [linked server],'SET FMTONLY OFF; EXEC (''USE DATABASE; DBCC showfilestats WITH NO_INFOMSGS '')')

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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