A small example in SQL Server that uses exec to handle variables contained in a _mssql

Source: Internet
Author: User

SQL Server, use exec to handle a variable in the SQL string, hint: The scalar variable must be declared @ (resolved!) )

Copy Code code as follows:

declare @tssj nvarchar (100)--External variables
declare @Sql_Sql nvarchar (100)--Save SQL string variable

Set @Sql_Sql =n ' select @tssj =jpk from b where bzmc= ' China '

EXEC sp_executesql @Sql_Sql, N ' @tssj int output ', @tssj output
Select @tssj

N ' @tssj int output ', @tssj output
This sentence is the key, is passed the variable parameter and the outgoing variable parameter!

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.