SQL Where in (1,2,3,4) 换成字段一列的值
DECLARE @resource VARCHAR(300) ; SELECT @ resource = SUBSTRING(CourseIdList, 1, LEN(CourseIdList) - 1) SELECT SUM(rlong * 60) FROM r_resource WHERE id IN ( @resource) 换成 DECLARE @resource VARCHAR(300) ; SELECT @ resource = SUBSTRING(CourseIdList, 1, LEN(CourseIdList) - 1) SELECT @SumStudyTime = SUM(rlong * 60) FROM r_resource where charindex(','+cast(id as varchar(10))+',',','+@resource+',')>0 SELECT cid,id FROM dbo.test where charindex(','+CAST(Cid AS varchar(10))+',',',3,')>0 注释:cid 前后加上 逗号,在后面的字符创中获取下标