有个字段叫 manIds
列格式是
row1 [1][12][23][34][45][56][56]
row2 [34][56]
row2 [34][45][56]
row2 [34][45]
用一句SLQ查出NAME含[45] 的列
LIKE该怎么写????
------解决方案--------------------
----------------------------
-- 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 行受影响)
*/
------解决方案--------------------

------解决方案--------------------
1樓的可以,通過chinindex.
------解决方案--------------------
charindex可以,like不行,因為like 下_ % [] ^屬於特殊字符
------解决方案--------------------

----------------------------
-- 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]'
--------------开始查询--------------------------