SQL-sp_executesql

原文链接:http://www.cnblogs.com/LifeDecidesHappiness/p/9479631.html
1.SQL
/*
    人员:LDH
    功能:SQL-sp_executesql介绍和使用
    日期:2018-8-15
 */

USE TestDB;
GO

DECLARE @sql NVARCHAR(2000);
DECLARE @cou INT;
DECLARE @id INT;

SET @id = 1;
SET @sql = 'SELECT @count=COUNT(1) FROM Person WHERE Id = @id';

EXEC sp_executesql @sql, N'@count int out,@id int', @cou OUT, @id;

PRINT @cou;
2.运行结果

SQL-sp_executesql

转载于:https://www.cnblogs.com/LifeDecidesHappiness/p/9479631.html

上一篇:存储过程、插入数据后直接过去主键id


下一篇:SQL经典练习题50--mysql