问题是补是这样?如有相同,则查询最大的编号,然后加1,INSERT
否则直接INSERT

解决方案 »

  1.   

    insert into table(GroupName,NumInGroup)
    Select 'QQ',
    Case
    when (select Count(*)from table where groupName='A' and NumInGroup =QQ.numInGroup)=0 then QQ.numInGroup
    when (select Count(*)from table where groupName='A' and NumInGroup =QQ.numInGroup)>0 then (select Count(*)from table where groupName='A')+1
       From QQTable
      

  2.   

    when (select Count(*)from table where groupName='A' and NumInGroup =QQ.numInGroup)>0 then (select Count(*)from table where groupName='A')+1
       From QQTable修改為
    when (select Count(*)from table where groupName='A' and NumInGroup =QQ.numInGroup)>0 then (select max(NumInGroup)from table where groupName='A')+1 END
       From QQTable
      

  3.   

    insert into table(GroupName,NumInGroup)
    values(@qq,
    case
    when exists(select numIngroup from QQtable where groupName='A' and NumInGroup =@numInGroup) then @numInGroup
    else  (select Max(NumInGroup)+1 from table where groupName='A')
    )
    2: if exists(select numIngroup from QQtable where groupName='A' and NumInGroup =@numInGroup) 
     select @numInGroup=max(NumInGroup)+1 from QQtable  insert into QQtable
     values
     (@qq,@numInGroup)
       2:
      

  4.   

    看看这里,是否对你有帮助
    这样的要求用触发器实现很方便http://expert.csdn.net/Expert/topic/1131/1131325.xml?temp=.5935022
      

  5.   

    update x
    set GroupName='A',NumInGroup=case
       when exists (select * from tablename where GroupName='A' and NumInGroup=x.NumInGroup) then isnull((select max(NumInGroup) from tablename where  GroupName='A'),0)+1 
       else a.NumInGroup 
       end
    from tablename x
    where x.name='qq'