各位大侠帮我看看这个存储过程的问题到底出在哪?检查过了明明没有语法错误,但在SQLCOMMAND  里面就是执行不了!
CREATE  PROCEDURE   RepIn
(
     @TopID int,
     @Tem     int,
     @Yeshu       int
)AS
BEGIN
Declare  @sql  varchar(8000)
SET @sql= 'select  top ' + @Tem+'   *    FROM repInfo
where id not in(select top'+ @Yeshu+' id from repInfo where  文章id='+@TopID+' ORDER BY ID) AND 文章id='+@TopID+' order by id'EXEC @sql
END
GO

解决方案 »

  1.   

    exec 执行sql好象不对
    只能 exec 存储过程
      

  2.   

    CREATE  PROCEDURE   RepIn
    (
         @TopID int,
         @Tem     int,
         @Yeshu       int
    )AS
    BEGIN
    Declare  @sql  varchar(8000)
    SET @sql= 'select  top ' + convert(nvarchar, @Tem )+'   *    FROM repInfo
    where id not in(select top '+ convert(nvarchar, @Yeshu ) +' id from repInfo where  文章id= '+ convert(nvarchar, @TopID ) +' ORDER BY ID) AND 文章id='+@TopID+' order by id'EXEC (@sql )--执行Sql语句需要括号,执行存储过程不需要括号
    END
    GO