日期:2014-05-17  浏览次数:20579 次

在线求指教..这种情况要怎么来批量处理??
class01   class02   class03
101         10101     10101001
101         10101     10101002
101         10101     10101003
102         10201     10201001
102         10201     10201002
103         10301     10301001
103         10301     10301002
103         10301     10301003

怎么根据class01和class02来得到class03的值???

------解决方案--------------------

;with cte(class01,class02) as
(
select 101,10101
union all select 101,10101
union all select 101,10101
union all select 102,10201
union all select 102,10201
union all select 103,10301
union all select 103,10301
union all select 103,10301
)
select class01,class02
,class03=cast(class02 as varchar)+RIGHT('00'+cast(rn as varchar),3)
from 
(
select *,rn=ROW_NUMBER() over(partition by class01,class02 order by getdate()) from cte
)t

/*
class01 class02 class03
101 10101 10101001
101 10101 10101002
101 10101 10101003
102 10201 10201001
102 10201 10201002
103 10301 10301001
103 10301 10301002
103 10301 10301003
*/

------解决方案--------------------
----------------------------------------------------------------
-- Author  :DBA_Huangzj(發糞塗牆)
-- Date    :2013-11-18 17:51:47
-- Version:
--      Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 
-- Dec 28 2012 20:23:12 
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go 
create table [huang]([class01] int,[class02] int,[class03] int)
insert [huang]
select 101,10101,10101001 union all
select 101,10101,10101002 union all
select 101,10101,10101003 union all
select 102,10201,10201001 union all
select 102,10201,10201002 union all
select 103,10301,10301001 union all
select 103,10301,10301002 union all
select 103,10301,10301003
--------------开始查询---