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  前后加上 逗号,在后面的字符创中获取下标
       

 

posted @ 2018-06-04 16:58  天豪  阅读(2263)  评论(0编辑  收藏  举报