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)