问题是补是这样?如有相同,则查询最大的编号,然后加1,INSERT
否则直接INSERT
否则直接INSERT
解决方案 »
- join 连接查询的问题 大家来帮忙看下
- sql server 2005 windows身份验证的问题,谢谢
- 插入10000*150条数据时出的错!
- 一个sql语句把我难住了?distrinct
- 小问题???求高手指教 急急急,---在线等待
- 在线急等--几个菜鸟问题,不知如何解决.
- 关于自定义函数的问题
- select top.........????
- 日志满了怎么办?
- 各位数据库版的ggdddjjmm,偶是牛虻,问题极菜,都是基本问题,分数极多,没放过低于100的贴子,偶正在学sql server,希望大家帮帮偶//牛虻
- 向一个非空表中insert数据,如何判断哪些数据是刚刚填入的?
- 在WIN98下安装MS SQL2000个人版,在配置服务器时出现缺少sqlunirl.dll为何,请高人指教!
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
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
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:
这样的要求用触发器实现很方便http://expert.csdn.net/Expert/topic/1131/1131325.xml?temp=.5935022
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'