34,838
社区成员




create table ta(id int, bm varchar(30))
go
insert into ta select 1, '01'
insert into ta select 1, '01212'
insert into ta select 1, '013343'
insert into ta select 1, '01212333'
--下面语句中除了“自定义录入的值”以外,其他都是固定的,无法改变的。
select * from ta where bm like '自定义录入的值%'
--只在“自定义录入的值”上做文章,可否使上述语句检索出如下内容:
id bm
----------- ------------------------------
1 01
(所影响的行数为 1 行)
--模糊
declare @Paramenter nvarchar(20)
set @Paramenter='01'
select * from ta where bm like @Paramenter+'%'
go
--精准
declare @Paramenter nvarchar(20)
set @Paramenter='01[^0-9]'
select * from ta where bm like @Paramenter+'%'
create table ta(id int, bm varchar(30))
go
insert into ta select 1, '01'
insert into ta select 1, '01212'
insert into ta select 1, '013343'
insert into ta select 1, '01212333'
DECLARE @p VARCHAR(20)
SET @p='01'
select TOP 1 * from ta where bm like @p+'%' ORDER BY LEN(bm)-LEN(@p)
--DROP TABLE ta