我可以在存储过程中使用以下语法吗,
set @count = (select count(*) from [dbo].[employee] where @column_name ='T')
答案 0 :(得分:2)
CREATE PROCEDURE Proc_Name
@Column_Name NVARCHAR(128),
@COUNT INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Sql NVARCHAR(MAX);
SET @Sql = N'SELECT @count = count(*) from [dbo].[employee] where ' + QUOTENAME(@Column_Name)
+ N' =''T'''
EXECUTE sp_executesql @Sql
,N'@COUNT INT OUTPUT'
,@COUNT OUTPUT
END