Create PROCEDURE [dbo].[A_Count] -- Add the parameters for the stored procedure here @TableID NVARCHAR(128), --表名称 @Column NVARCHAR(4000), --显示字段名称 @Where NVARCHAR(1024) --查询条件 AS BEGIN DECLARE @Str NVARCHAR(4000) SET @Str="SELECT ISNULL(COUNT(*),0) FROM("; SET @Str = @Str + " SELECT " + @Column + " FROM " + @TableID; SET @Str = @Str + ") A"; IF(@Where <> "") --假如查询条件不为空时 BEGIN SET @Str = @Str + " WHERE " + @Where; END EXEC(@Str) END
解决方案
30
要改成相似这样的:
CREATE DEFINER=`root`@`%` PROCEDURE `getdate`(v_limit int) BEGIN set @a = "select * from tb2 where id =?"; set @b =v_limit; prepare s from @a; execute s using @b; deallocate prepare s; END$$