例如数据如下:
0 3M00059-2028A-1.24C 2
1 3M00059-2028A-1.24C 2
2 3M00059-2028A-1.24A 3
3 3M00059-2028A-1.25B 3
4 3M00059-2028A-1.25C 4
5 3M00062-2028A-1.25C 1
6 3M00063-2030A-1.25C 1
7 3M00063-2030A-1.26B 1
8 3M00065-2028A-1.26C 2
9 3M00065-2028A-1.27A 1
10 3M00065-2028A-1.27B 1
11 3M00068-2028A-1.28A 1
12 3M00068-2028A-1.28B 1
13 3M00068-2028A-1.29C 2
14 3M00068-2028A-1.29C 2
15 3M00068-2028A-1.29A 2
我想对第2列最后3个数字提取分类:
结果为
24 C 2
24 C 2
25 C 4
25 C 1
25 C 1
26 C 2
29 C 2
29 C 2
24 A 3
27 A 1
28 A 1
.......
希望得到大家的帮助。谢谢大家
------解决方案--------------------
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-04-04 13:38:24
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] int,[a] nvarchar(38),[b] int)
insert [huang]
select 0,'3M00059-2028A-1.24C',2 union all
select 1,'3M00059-2028A-1.24C',2 union all
select 2,'3M00059-2028A-1.24A',3 union all
select 3,'3M00059-2028A-1.25B',3 union all
select 4,'3M00059-2028A-1.25C',4 union all
select 5,'3M00062-2028A-1.25C',1 union all
select 6,'3M00063-2030A-1.25C',1 union all
select 7,'3M00063-2030A-1.26B',1 union all
select 8,'3M00065-2028A-1.26C',2 union all
select 9,'3M00065-2028A-1.27A',1 union all
select 10,'3M00065-2028A-1.27B',1 union all
select 11,'3M00068-2028A-1.28A',1 union all
select 12,'3M00068-2028A-1.28B',1 union all
select 13,'3M00068-2028A-1.29C',2 union all
select 14,'3M00068-2028A-1.29C',2 union all
select 15,'3M00068-2028A-1.29A',2
--------------生成数据--------------------------
select REVERSE(SUBSTRING(REVERSE(a),2,PATINDEX('%.%',REVERSE(a))-2)),LEFT(REVERSE(a),1) AS a,b
from [huang]
----------------结果----------------------------
/*
-------------------------------------- ---- -----------
24 C 2
24 C 2
24 A 3
25 B 3
25 C 4
25 C 1
25 C 1