select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=3 and PaperDegree ='3' and KnowledgeTypeId in(2,3,4)union all
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=4 and PaperDegree ='4' and KnowledgeTypeId in(2,3,4)union all
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=5 and PaperDegree ='5'
我的查询语句是这样的, 我写的是一个存储过程
我传值进去的时候,例如 @QuestionTypeId varchar(50),它的值是'3,4,5',(也有可能是 '4,5,6,7 '),也就是QuestionTypeId 的条件字段,根据 ','来分割,在存储过程里面应该怎么分割呢?我希望做到的是 如果传递的值是 '3,4' 那么 查询语句就是
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=3 and PaperDegree ='3' and KnowledgeTypeId in(2,3,4)union all
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=4 and PaperDegree ='4' and KnowledgeTypeId in(2,3,4)
如果传递的值是'3,4,5',那么查询语句就是
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=3 and PaperDegree ='3' and KnowledgeTypeId in(2,3,4)union all
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=4 and PaperDegree ='4' and KnowledgeTypeId in(2,3,4)union all
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=5 and PaperDegree ='5'
传递值具体是不确定的,有可能是 '3,4',也有可能是'3,4,5,6',也有可能是'3,4,5,6,7'
这样该怎么写呢?
繁星淼淼
慕无忌1623718
慕斯王