表a,字段a_b,varchar型,存放数字字符串,如下:a_id a_b
1 00077
2 00078
3 00076
4 00079
...插入新记录时,如何得到a_b字段的最大值,并自动加1后插入注意,a_b是VARCHAR型。谢谢
1 00077
2 00078
3 00076
4 00079
...插入新记录时,如何得到a_b字段的最大值,并自动加1后插入注意,a_b是VARCHAR型。谢谢
调试欢乐多
insert @a select 1 ,'00077'
union all select 2 ,'00078'
union all select 3 ,'00076'
union all select 4 ,'00079'
select right('0000'+ltrim(cast(max(a_b) as int)+1),5) from @a
select right(100000 + max(a_b) + 1,5) from tableA
from a
for insert
as
update a
set a_b= select right('0000'+ltrim(cast(max(a_b) as int)+1),5) from a
where a_id=@@identity
http://community.csdn.net/Expert/topic/5645/5645320.xml?temp=.3341181