--存储过程名不要和变量一样
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 

解决方案 »

  1.   

    --字符串前后要加引号,
    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') 
      

  2.   

    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