sp_prepexec
Used to prepare and execute a parameterized SQL statement. This command combines the functions of the sp_prepare and sp_execute procedures and is available from SQL2000 onwards.
Syntax
sp_prepexec [@handle =] statement_handle OUTPUT,
[@paramdef =] N'parameter_name data_type, [,...n]'
[@stmt =] N'stmt',
{, [@param1 =] value1 [,...n] }
Arguments
- [@handle =] statement_handle
- Is the name of a declared integer variable to receive the statement handle. statement_handle is int, with no default.
- [@paramdef =] N'parameter_name data_type [,...n]'
- Is one string that contains the definitions of all parameters that have been embedded in stmt. Each parameter definition consists of a parameter name and a data type. n is a placeholder indicating additional parameter definitions. Every parameter specified in stmt must be defined in @paramdef.
- [@stmt =] 'stmt'
-
Is a string containing a valid SQL statement. The size of the string is limited only by available database server memory. stmt can contain parameters having the same form as a variable name, for example:
'SELECT * FROM Employees WHERE EmployeeID = @IDParameter'
Each parameter included in stmt must have a corresponding entry in both the @paramdef parameter definition list.
- [@param1 =] value1
- Is a value for the first parameter defined in the parameter string. The value can be a constant or a variable. There must be a parameter value supplied for every parameter included in stmt. The values are not needed if the Transact-SQL statement in stmt has no parameters.
- n
- Is a placeholder for the values of additional parameters. Values can be only constants or variables. Values cannot be more complex expressions such as functions, or expressions built using operators.
Return Code Values
0 (success) or 1 (failure).
Result Sets
Returns a result set if specified by the prepared statement.
Permissions
Execute permissions default to the public role.
Example
'DB > MS-SQL' 카테고리의 다른 글
조건문과 함께 임시 테이블의 사용시 주의할 점. (0) | 2009.01.01 |
---|---|
연결된 서버의 저장 프로시저를 호출하기. (0) | 2008.12.31 |
Undocumented 저장 프로시저 : sp_MSforeachtable, sp_MSforeachdb (0) | 2008.10.07 |
MS SQL Server 2005의 데이터베이스 미러링 (0) | 2008.10.07 |
MS-SQL 서버의 버전을 확인하는 방법 (0) | 2008.09.03 |