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

用查詢語句實現流水號字段,怎么做

2012-01-09 
用查詢語句實現流水號字段,如何做效果如下:f1f2f3ab0001cd0002ef0003ag0004要求:隻能用select語句。[解决办

用查詢語句實現流水號字段,如何做
效果如下:
f1       f2         f3
a         b           0001
c         d           0002
e         f           0003
a         g           0004

要求:隻能用select語句。

[解决办法]
select rigth( '000 ' + ltrim(cast(max(f3) as int) + 1), 4) from table
[解决办法]
echiynn(寶琲) ( ) 信誉:100 Blog 加为好友 2007-07-12 09:52:12 得分: 0


select rigth( '000 ' + ltrim(cast(max(f3) as int) + 1), 4) from table



----------
你這樣只能到0009,再後面的就不行了
[解决办法]
select f1,f2,(select right(10000+count(1),4) from tb where f2 <=a.f2) f3 from tb a order by f3
[解决办法]
select cast(id as int) from t1

热点排行