System stored procedure, sp_executesql

Source: Internet
Author: User

System stored procedure, sp_executesql
The language is here!

Sp_executesql
Execute statements or batch processing that can be reused multiple times or dynamically generated. Transact-SQL statements or batch processing can contain embedded parameters.

Syntax
Sp_executesql [@ stmt =] stmt
[
{, [@ Params =] n' @ parameter_name data_type [,... N] '}
{, [@ Param1 =] 'value1' [,... n]}
]

Parameters
[@ Stmt =] stmt

A Unicode string that contains a Transact-SQL statement or batch processing. stmt must be a Unicode constant or variable that can be implicitly converted to ntext. More complex Unicode expressions are not allowed (for example, concatenating two strings using the + operator ). Character constants are not allowed. If a constant is specified, N must be used as the prefix. For example, the Unicode constant n'sp _ who 'is valid, but the character constant 'SP _ who' is invalid. The size of the string is limited only by the memory of the available database server.

Stmt can contain parameters in the same format as the variable name, for example:

N 'select * FROM Employees WHERE EmployeeID = @ IDParameter'

Each parameter contained in stmt must have a corresponding item in the @ params Parameter definition list and Parameter Value List.

[@ Params =] n' @ parameter_name data_type [,... N]'

String that contains the definitions of all parameters embedded in stmt. This string must be a Unicode constant or variable that can be implicitly converted to ntext. Each parameter definition consists of the parameter name and data type. N is a placeholder for the additional parameter definition. Each parameter specified in stmt must be defined in @ params. If the Transact-SQL statement or batch processing in stmt does not contain parameters, @ params is not required. The default value of this parameter is NULL.

[@ Param1 =] 'value1'

The value of the first parameter defined in the parameter string. The value can be a constant or variable. Parameter values must be provided for each parameter in stmt. If there is no parameter in the Transact-SQL statement or batch processing contained in stmt, no value is required.

N

The placeholder of the value of the additional parameter. These values can only be constants or variables, not more complex expressions, such as functions or expressions generated using operators.

Return code value
0 (successful) or 1 (failed)

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.