首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

流水号的有关问题。

2012-03-29 
流水号的问题。在线等。T1表如下:IDwh107050100012070501000230705010003其中wh为char(10)wh前六位为年月日

流水号的问题。在线等。
T1表如下:
ID       wh
1         0705010001  
2         0705010002  
3         0705010003  
其中wh为char(10)
wh前六位为年月日后四位为流水号

现在我要新增记录?(当天最大的流水怎样得到)

[解决办法]
max(RIGHT( '0705010003 ',4))
[解决办法]
select max(wh) from t1
[解决办法]
select max(RIGHT(wh,4)) from T1 ??

[解决办法]
insert into T1(wh)
select right( '000 '+rtrim(cast(isnull(right(max(wh),4),0) as int)+1),4)
from T1
where left(wh,6)=convert(char(6),cast( '2007-05-02 ' as datetime),12)

[解决办法]
create table T1(wh char(10))
insert into T1
select '0705010001 '
union all select '0705010002 '
union all select '0705010003 '

insert into t1
select isnull(left(max(wh),6)+right( '0000 '+cast(cast(right(max(wh),4) as int)+1 as varchar(4)),4),right(replace(convert(char(10),getdate(),21), '- ', ' '),6)+ '0001 ')
from t1
where left(wh,6)=right(replace(convert(char(10),getdate(),21), '- ', ' '),6)

select * from t1

drop table t1

热点排行
Bad Request.