select 1 from sysobjects where id=object_id('table') and xtype='U'
注:在查询分析器里能正常执行,现在需要把上句组成一个字符串,怎么写?

解决方案 »

  1.   

    什么意思CString strSQL = _T("select 1 from sysobjects where id=object_id('table') and xtype='U'");??
      

  2.   

    SQL Server里的写法:
    declare @str varchar(200)
    SET @str = 'select 1 from sysobjects where id=object_id('table') and xtype='U''
    这句不对,其实就是字串里套字串的问题。
      

  3.   

    declare @str varchar(200)
    SET @str = "select 1 from sysobjects where id=object_id('table') and xtype='U'"
      

  4.   

    字符串里的字符串,把 ' 写作 '' 就可以
    SET @str = 'select 1 from sysobjects where id=object_id(''table'') and xtype=''U'''
      

  5.   

    SQL Server中,由于字符串是用两个单引号阔起来的(不能用双引号),所以必须对字符串中的单引号进行处理,方法是用两个连着的单引号替换一个单引号。例如:
    I'm a man.需写成I''m a man.