日期:2014-05-18  浏览次数:20369 次

查询表是否存在的问题
泪奔。。。

SQL code
exec('
    if(object_id('##tableName','u') is not null)
    begin
       truncate '##tableName'
    end
    else
    begin
       create table ##tableName
       (
           whID,int
       )
    end
')


这里明显有错!单引号嵌套!
但是,要怎么修改才能正确啊???
在线等解答。

------解决方案--------------------
SQL code

exec('
    if(object_id(''##tableName'',''u'') is not null)
    begin
       truncate table ##tableName
    end
    else
    begin
       create table ##tableName
       (
           whID int
       )
    end
')