Problems encountered by SQL Server using OPENQUERY or OPENROWSET

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.