日期:2014-05-18 浏览次数:20402 次
--存储过程名不要和变量一样 CREATE PROCEDURE [dbo].[sproLocation] ( @Topcount int, @Location char(50) ) as declare @strCounter varchar(10) set @strCounter=convert(varchar(10),@Topcount) exec('select top '+'('+@strCounter+')'+' * from tt where [_FontOrImage]=1 and [Location]='+@Location+'Order By _Start_Time Desc') GO
------解决方案--------------------
--字符串前后要加引号, exec('select top '+@strCounter+' * from tt where [_FontOrImage]=1 and [Location]='+@Location+' Order By _Start_Time Desc') ---> exec('select top '+@strCounter+' * from tt where [_FontOrImage]=1 and [Location]='''+@Location+''' Order By _Start_Time Desc')
------解决方案--------------------
CREATE PROCEDURE Location ( @Topcount int, @Location char(50) ) as declare @strCounter varchar(10) set @strCounter=convert(varchar(10),@Topcount) exec('select top '+@strCounter+' * from tt where [_FontOrImage]=1 and [Location]='''+@Location+''' Order By _Start_Time Desc') GO