日期:2014-05-17 浏览次数:20818 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-11-15 11:01:44
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[TempTable]
if object_id('[TempTable]') is not null drop table [TempTable]
go
create table [TempTable]([ID] varchar(6),[Name] varchar(4))
insert [TempTable]
select 'GL001','一' union all
select 'GHK01','二' union all
select 'MN_OP','三' union all
select 'GL002','四' union all
select 'GL003','五' union all
select 'GL004','六' union all
select 'GHK02','七' union all
select 'GHK03','八' union all
select 'MLKPO','九' union all
select 'L_PO09','十' union all
select 'GL005','十一'
--------------开始查询--------------------------
select cast('GL' + right('00'+rtrim(SUBSTRING(max(id),3,3) + 1),3) as nvarchar(20))
from [TempTable]
where id like 'GL%'
-