---------------------------------------------------------------- -- Author :DBA_HuangZJ(发粪涂墙) -- Date :2014-04-01 16:28:21 -- Version: -- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) -- Apr 2 2010 15:48:46 -- Copyright (c) Microsoft Corporation -- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor) -- ---------------------------------------------------------------- --> 测试数据[huang] if object_id('[huang]') is not null drop table [huang] go create table [huang]([商品ID] nvarchar(42)) insert [huang] select '2,5,23,66,777,34,9,87' union all select '55,66,104,4,223' union all select '2' --------------生成数据--------------------------select * from [huang] WHERE charindex(','+'66,104'+',',商品ID)>0 ----------------结果---------------------------- /* 商品ID ------------------------------------------ 55,66,104,4,223*/
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-04-01 16:28:21
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([商品ID] nvarchar(42))
insert [huang]
select '2,5,23,66,777,34,9,87' union all
select '55,66,104,4,223' union all
select '2'
--------------生成数据--------------------------select * from [huang] WHERE charindex(','+'66,104'+',',商品ID)>0
----------------结果----------------------------
/*
商品ID
------------------------------------------
55,66,104,4,223*/