当前位置: 代码迷 >> Sql Server >> 变量的SQL语句exec老是提示语法异常,麻烦大家看看
  详细解决方案

变量的SQL语句exec老是提示语法异常,麻烦大家看看

热度:81   发布时间:2016-04-27 20:22:28.0
变量的SQL语句exec老是提示语法错误,麻烦大家看看
declare   @csql   varchar(8000),@topn   varchar(10)
set   @topn   =   10
set   @csql   =   'insert   into   traff(bh,tf,t1,t2,t34,t50,t8)   select   top   '[email protected]+ '   ' 'SJ-07070003 ' '   as   bh, ' 'SJ-07070003001 ' '   as   tf, ' '20 ' '   as   t1, ' '48 ' '   as   t2, ' '24F0TXUB3 ' '   as   t34, ' 'fedr ' '   as   t50,2200   as   t8   from   sysid   where   not   exists(select   *   from   traff   where   traff.tf   like   ' 'SJ-0707____ ' '+Right(10001+sysid.id-1,4)) '
exec   @csql


上面的语句执行后,老是提示:


服务器:   消息   203,级别   16,状态   2,行   5
名称   'insert   into   traff(bh,tf,t1,t2,t34,t50,t8)   select   top   10   'SJ-07070003 '   as   bh, 'SJ-07070003001 '   as   tf, '20 '   as   t1, '48 '   as   t2, '24F0TXUB3 '   as   t34, 'fedr '   as   t50,2200   as   t8   from   sysid   where   not   exists(select   *   from   traff   where   traff.tf   like   'SJ-0707____ '+Right(10001+sysid.id-1,4)) '   不是有效的标识符。


请问问题出在哪里????



------解决方案--------------------
exec @csql
改为:
exec(@csql)
------解决方案--------------------
exec (@csql)
  相关解决方案