日期:2014-05-17 浏览次数:20595 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-01-19 14:34:43
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([manIds] varchar(27))
insert [huang]
select '[1][12][23][34][45][56][56]' union all
select '[34][56]' union all
select '[34][45][56]' union all
select '[34][45]'
--------------开始查询--------------------------
select * from [huang] WHERE CHARINDEX('[45]',manids,1)>0
----------------结果----------------------------
/*
manIds
---------------------------
[1][12][23][34][45][56][56]
[34][45][56]
[34][45]
(3 行受影响)
*/
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-01-19 14:34:43
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([manIds] varchar(50))
insert [huang]
select '[1][12][23][34][45][56][56]' union ALL
select '[4545]' union ALL
select '[34][56]' union all
select '[34][45][56]' UNION all
select '[34][45]'
--------------开始查询--------------------------