接着昨天的问题今天再问一下
我先贴出我的测试数据出来:
bil_no voh_no sq_no voh_dd voh_flag
MK-20120204-1-00001MK-20120204-1-00001000012012-02-04 14:16:06.520现
MK-20120204-1-00002MK-20120204-1-00002000022012-02-04 14:19:42.443现
MK-20120204-3-00001MK-20120204-3-00001000012012-02-04 14:17:38.493转
MK-20120206-1-00001MK-20120206-1-00001000012012-02-06 09:23:37.207现
MK-20120206-1-00002MK-20120206-1-00002000022012-02-06 09:32:40.907现
MK-20120206-1-00003MK-20120206-1-00003000032012-02-06 09:35:36.970现
MK-20120206-1-00004MK-20120206-1-00004000042012-02-06 10:34:51.530现
MK-201202-3-0001 MK-201202-3-0001 00012012-02-13 13:54:10.987转
MK-201202-3-0002 MK-201202-3-0004 -00022012-02-13 14:19:50.327转
MK-201202-3-0003 MK-201202-3-0006 -00032012-02-13 14:19:50.387转
MK-201202-3-0004 MK-201202-3-0004 -00042012-02-13 14:19:50.433转
MK-201202-3-0005 MK-201202-3-0005 -00052012-02-13 14:19:50.507转
MK-201202-3-0006 MK-201202-3-0006 -00062012-02-13 14:19:50.560转
MK-201202-3-0007 MK-201202-3-0007 -00072012-02-13 14:22:31.780转
MK-201202-3-0008 MK-201202-3-0008 -00082012-02-13 14:22:43.070转
MK-201202-3-0009 MK-201202-3-0009 -00092012-02-13 14:27:30.250转
另外个表:
ITM VOG_FLAG
1 现
2 银
3 转
我想要的结构是 MK-201202-1-0001 比如第一条数据 VOH_NO:MK-20120204-1-00001 我要修改成:MK-201202-1-0001 需要判断它是不是这个月的第一个单据日期就 根据voh_dd这个字段来判断当前日期是不是最小的然后再进行累加,MK-201202-3-0002 MK-201202-3-0004 -0002像这条数据就改成 MK-201202-3-0002(这个功能实现了)最要是前面的更新,还有个问题如果是满月了跳到下一个月的不知道怎么处理了?
[解决办法]
没怎么看明白你的需求
[解决办法]
select new_no='MK-'+convert(varchar(6),voh_dd,112)+'-'+ltrim(b.[ITM])+'-'+right('0000'+row_number() over(partition by convert(varchar(6),voh_dd,112) order by voh_dd),4) from [ta] a,[tb] b where a.[voh_flag]=b.[VOG_FLAG]/*new_no-------------------------------MK-201202-1-1MK-201202-3-2MK-201202-1-3MK-201202-1-4MK-201202-1-5MK-201202-1-6MK-201202-1-7MK-201202-3-8MK-201202-3-9MK-201202-3-10MK-201202-3-11MK-201202-3-12MK-201202-3-13MK-201202-3-14MK-201202-3-15MK-201202-3-16(16 行受影响)*/