日期:2014-05-18 浏览次数:20664 次
CREATE PROCEDURE AA ( @PAGE INT, @CURRENT INT ) DECLARE @STR NVARCHAR(1000) IF (PAGE='1') IF (CURRENT='0') STR='SELECT * FROM TABLE' EXEC sp_executesql @STR
CREATE PROCEDURE AA ( @PAGE INT, @CURRENT INT ) DECLARE @STR NVARCHAR(1000) SET @STR='SELECT * FROM TABLE2' IF (PAGE='1') IF (CURRENT='0') STR='SELECT * FROM TABLE' EXEC sp_executesql @STR
CREATE PROCEDURE AA @PAGE INT, @CURRENT INT as DECLARE @STR NVARCHAR(1000) SET @STR='SELECT * FROM TABLE2' IF (@PAGE='1') IF (@CURRENT='0') @STR='SELECT * FROM TABLE' EXEC sp_executesql @STR
------解决方案--------------------
变量名必须以@开头,这是规定.
@@开头是全局
@开头是局部
------解决方案--------------------
CREATE PROCEDURE AA ( @PAGE INT, @CURRENT INT ) AS DECLARE @STR NVARCHAR(1000) IF (PAGE='1') and (CURRENT='0') set @STR='SELECT * FROM TABLE' else set @STR='SELECT * FROM TABLE2' EXEC sp_executesql @STR