--谁对谁错,一测试就知道了.--测试 declare @t table(zbhao varchar(9)) insert @t select '040329001' union all select '040327001' union all select null--中海的 select isnull(cast(max(zbhao)+1 as varchar(100)),'040329001') from @t where zbhao like '040327%'--我的 select isnull(right('000000000'+cast(max(zbhao)+1 as varchar),9),'040329001') from @t where zbhao like '040327%'/*--测试结果----------------------------- 40327002(所影响的行数为 1 行) ------------------ 040327002(所影响的行数为 1 行) --*/
select right('000000000'+cast(40329001 as varchar),9)--结果:040329001
--谁对谁错,一测试就知道了.--测试 declare @t table(zbhao varchar(9)) insert @t select '040329001' --union all select '040327001' union all select null--中海的 select isnull(cast(max(zbhao)+1 as varchar(100)),'040329001') from @t where zbhao like '040327%'--我的 select isnull(right('000000000'+cast(max(zbhao)+1 as varchar),9),'040329001') from @t where zbhao like '040327%'/*--测试结果------------------------- 040329001(所影响的行数为 1 行) ------------------ 040329001(所影响的行数为 1 行) --*/
declare @t table(zbhao varchar(9))
insert @t select '040329001'
union all select '040327001'
union all select null--中海的
select isnull(cast(max(zbhao)+1 as varchar(100)),'040329001')
from @t where zbhao like '040327%'--我的
select isnull(right('000000000'+cast(max(zbhao)+1 as varchar),9),'040329001')
from @t where zbhao like '040327%'/*--测试结果-----------------------------
40327002(所影响的行数为 1 行)
------------------
040327002(所影响的行数为 1 行)
--*/
declare @t table(zbhao varchar(9))
insert @t select '040329001'
--union all select '040327001'
union all select null--中海的
select isnull(cast(max(zbhao)+1 as varchar(100)),'040329001')
from @t where zbhao like '040327%'--我的
select isnull(right('000000000'+cast(max(zbhao)+1 as varchar),9),'040329001')
from @t where zbhao like '040327%'/*--测试结果-------------------------
040329001(所影响的行数为 1 行)
------------------
040329001(所影响的行数为 1 行)
--*/