update b set childarticlecount=(
select count(*) from article where article.regionkey like  ''% b.id %'') from region b这句话总是运行时提示对数据类型而言运算符无效。运算符为 modulo,类型为 nvarchar。应该怎么写啊?

解决方案 »

  1.   

    update b set childarticlecount=(
    select count(*) from article where charindex(b.id,regionkey )>0) from region b
      

  2.   

    update b set childarticlecount=(
    select count(*) from article where article.regionkey like  '% b.id %') from region b
      

  3.   


    update b set childarticlecount=(
    select count(*)
    from article
    where charindex(b.id,regionkey) > 0)
    region b
      

  4.   


    update b set childarticlecount=(
    select count(*)
    from article
    where charindex(b.id,regionkey) > 0)
    from region b
      

  5.   

    create table article
    (
    regionkey nvarchar(100)
    )
    insert article
    select '1 a 1' union all
    select '2 a 2'
    select '1 9 1' union all
    select '2 9 2'create table region
    (
    childarticlecount int,
    id int
    )
    insert region
    select null, 9--select * from article
    --select * from regionupdate b 
    set childarticlecount = (select count(*) from article where regionkey like  '% ' +  cast(b.id as varchar(10)) + ' %') 
    from region b/*
    childarticlecount id
    2 9
    */
      

  6.   

    article.regionkey like  ''% b.id %''
    ===》
    article.regionkey like  '%'+rtrim(b.id)+'%'