下面这条语句老是调试不过
老是提示like附近出错  到底错在哪里呢   set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Companywhere Place like %'+@strPlace+'%'
exec(@strSql)

解决方案 »

  1.   

    --try set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
    'select CompanyID, CompanyName,Address,Phone,Place from Companywhere Place like ''%'+@strPlace+'%'''
    exec(@strSql)
      

  2.   

    set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
    'select CompanyID, CompanyName,Address,Phone,Place from Company where Place like ''%'+@strPlace+'%'''
    exec(@strSql)
      

  3.   

    少空格啦!
    set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
    'select CompanyID, CompanyName,Address,Phone,Place from Company     where Place like %'+@strPlace+'%'
    exec(@strSql)
      

  4.   

    compnaywhere 中间应该有空格分开
      

  5.   

    怎么发上去这么乱,编辑一下 set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
    'select CompanyID, CompanyName,Address,Phone,Place from Company  
                   where Place like %'+@strPlace+'%'exec(@strSql)
      

  6.   

    因为本来正常情况下like后边就要有''来包含
    所以这里单引号涉及到变量的调用和字符串的填充,
    所以 Place like ''%'+@strPlace+'%''
      

  7.   

    set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place) '+
    'select CompanyID, CompanyName,Address,Phone,Place from Company  where Place like ''%'+@strPlace+'%'''
    exec(@strSql)
      

  8.   

    总结一下,正确语句为:
    set @strSql = 'insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
    'select CompanyID, CompanyName,Address,Phone,Place from Company where Place like ''%'+@strPlace+'%'''
    exec(@strSql)
    错误地方有2处:一个是where前没加空格; 另一个是两个%要加单引号。