日期:2014-05-19  浏览次数:20495 次

以下的一段sql为什么不可以执行
declare
@txt   char(1024)

set   @txt   =   'if   exists   (select   *   from   dbo.sysobjects   where   id   =   object_id(N "[dbo].[cmd] ")   and   OBJECTPROPERTY(id,   N "IsProcedure ")   =   1) '   +  
'   begin   '   +  
'   DROP   PROCEDURE   [dbo].[cmd]   '   +  
'   print   "cmd   sproc   exist,   drop   it " '   +  
'   end   '

exec   @txt


------解决方案--------------------
declare
@txt char(1024)

set @txt = 'if exists (select * from dbo.sysobjects where id = object_id(N ' '[dbo].[cmd] ' ') and OBJECTPROPERTY(id, N ' 'IsProcedure ' ') = 1) ' +
' begin ' +
' DROP PROCEDURE [dbo].[cmd] ' +
' print ' 'cmd sproc exist, drop it ' ' ' +
' end '

exec(@txt)
------解决方案--------------------
declare
@txt char(1024)

set @txt = 'if exists (select * from dbo.sysobjects where id = object_id(N ' '[dbo].[cmd] ' ') and OBJECTPROPERTY(id, N ' 'IsProcedure ' ') = 1) ' +
' begin ' +
' DROP PROCEDURE [dbo].[cmd] ' +
' print ' 'cmd sproc exist, drop it ' ' ' +
' end '

exec @txt