日期:2014-05-17 浏览次数:20734 次
T1 Id Name 1 1,2,3 2 4,5,6 3 7,8,9,10,11 --用一条sql语句找出name字段包含5的记录,有点难度吧 Id Name 2 4,5,6
DECLARE @T1 TABLE([ID] INT,[NAME] VARCHAR(11)) INSERT @T1 SELECT 1,'1,2,3' UNION ALL SELECT 2,'4,5,6' UNION ALL SELECT 3,'7,8,9,10,11' DECLARE @ID INT SET @ID=5 SELECT * FROM @T1 WHERE CHARINDEX(','+LTRIM(@ID)+',',','+NAME+',')>0 /* ID NAME ----------- ----------- 2 4,5,6 */