PCB MS SQL cross-Library Execute SQL Get return value

Source: Internet
Author: User

I. SQL cross-Library Execute SQL Get return value

DECLARE  @Dblink nvarchar( -)DECLARE  @sql nvarchar(MAX)DECLARE  @layer INTSET @Dblink = 'P2.fp_db.dbo.'Select @sql='SELECT top 1 @layer =layer from' + @Dblink + 'mktxhglb WHERE pdctno="'at00101ca0" "execsp_executesql@sqlN'@layer int Output',@layerOutputSELECT @layer

Use: sp_executesql Rule requirements:

1. require dynamic SQL and dynamic SQL parameter list must be nvarchar

2. The parameter list of dynamic SQL must be consistent with the order of parameter list of externally supplied values

3. Once the ' @name = value ' form is used, all subsequent parameters must be passed in the form of ' @name = value ', such as:

DECLARE  @Dblink nvarchar( -)DECLARE  @sql nvarchar(MAX)DECLARE  @layer INTSET @Dblink = 'P2.fp_db.dbo.'Select @sql='SELECT top 1 @layerNum =layer from' + @Dblink + 'mktxhglb WHERE pdctno="'at00101ca0" "execsp_executesql@stmt=@sql,@params=N'@layerNum int Output',@layerNum = @layerOutputSELECT @layer

PCB MS SQL cross-Library Execute SQL Get return value

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.