Openquery,openrowset allows the user to query on the linked server. This method is used to get the result set of the query.
1. In creating a stored procedure, you must set the
SET ANSI_NULLS on
SET ansi_warnings on
(Executed in Query Analyzer, these settings are activated by default)
2. Define a linked server (must have sysadmin privileges)
3. You can use it at this time
SELECT * from OPENQUERY (linkserver, ' EXEC mystoreproc ')
To get the result set returned by the stored procedure.
However, the stored procedure Mystoreproc cannot access the staging table.
If a temporary table is used, you must call the following
SELECT * from OPENQUERY (linkserver, ' SET fmtonly OFF; EXEC Mystoreproc ')
Generally speaking, OpenQuery is only accessed as a quick remote database, it must follow the Select, which means that a recordset needs to be returned.
Adding set Fmtonly off is used to mask the default setting that returns only column information, so that the returned output collection is submitted to the previous select display.
If you use the default setting, returning an empty collection causes the Select to fail, and the command cannot execute
Problems encountered by SQL Server using OPENQUERY or OPENROWSET