select [code] from [t1] where [code] like 'A[0-9]%'这样应该可以,太久没用了,不知道对不对,你可以试试
--> 测试数据:[TB] if object_id('[TB]') is not null drop table [TB] create table [TB]([code] varchar(12)) insert [TB] select 'A00001' union all select 'A00002' union all select 'AB0000000089' union all select 'ABC008'--当输入A的时候 declare @s varchar(10) set @s='A' select top 1 code from TB where patindex(@s+'[0-9]%',code)>0 order by code desc/* code ------------ A00002(所影响的行数为 1 行)*/--当输入AB的时候declare @s varchar(10) set @s='AB' select top 1 code from TB where patindex(@s+'[0-9]%',code)>0 order by code desc/*code ------------ AB0000000089(所影响的行数为 1 行)*/ drop table TB
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([code] varchar(12))
insert [TB]
select 'A00001' union all
select 'A00002' union all
select 'AB0000000089' union all
select 'ABC008'--当输入A的时候
declare @s varchar(10)
set @s='A'
select top 1 code from TB where patindex(@s+'[0-9]%',code)>0
order by code desc/*
code
------------
A00002(所影响的行数为 1 行)*/--当输入AB的时候declare @s varchar(10)
set @s='AB'
select top 1 code from TB where patindex(@s+'[0-9]%',code)>0
order by code desc/*code
------------
AB0000000089(所影响的行数为 1 行)*/
drop table TB