T-SQL Tutorial

T-SQL Sp_prepare


On Transact SQL language the sp_prepare is part of Database Engine Stored Procedures and prepares a parameterized statement and returns a statement handle for execution.

Sp_prepare syntax:

sp_prepare handle OUTPUT, params, statement, options ;





Sp_prepare example:

USE model;
GO
DECLARE @Param1 int;
EXEC sp_prepare @Param1 output,
N'@Param1 nvarchar(250), @Param2 nvarchar(250)',
N'SELECT database_id, name FROM sys.databases
WHERE name=@Param1 AND state_desc = @Param2';
EXEC sp_execute @Param1, N'Test', N'ONLINE';
GO