数据库中使用正则表达式
数据库中有一个字段有Tb23456,TBS123456,tasd1234,DFS1243456这些类型,过滤掉只要Tb23456这个类型的呢?
[解决办法]
如果你那些以逗号为间隔每行显示的话,直接where里面登于Tb23456就可以拉
[解决办法]
select * from 表 where 字段='Tb23456'
select * from 表 where left(字段,2) = 'Tb'
select * from [表名]
where patindex('tb%',[字段])>0 and
patindex('tbs%',[字段]) =0
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-11-28 11:30:45
-- 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]([a] varchar(10))
insert [huang]
select 'Tb23456' union all
select 'TBS123456' union ALL
select 'tasd1234' union all
select 'DFS1243456'
--------------开始查询--------------------------
select * from [huang] WHERE a LIKE 'tb[0-9]%'
----------------结果----------------------------
/*
a
----------
Tb23456
*/