第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

sql 查詢傳參數(shù)的問題

sql 查詢傳參數(shù)的問題

慕田峪7331174 2018-12-07 06:50:13
select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=3 and PaperDegree ='3' and KnowledgeTypeId in(2,3,4)union allselect top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=4 and PaperDegree ='4' and KnowledgeTypeId in(2,3,4)union allselect top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=5 and PaperDegree ='5'? 我的查詢語句是這樣的, 我寫的是一個存儲過程我傳值進(jìn)去的時候,例如 @QuestionTypeId varchar(50),它的值是'3,4,5',(也有可能是 '4,5,6,7 '),也就是QuestionTypeId 的條件字段,根據(jù) ','來分割,在存儲過程里面應(yīng)該怎么分割呢?我希望做到的是 如果傳遞的值是 '3,4' 那么 查詢語句就是 select top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=3 and PaperDegree ='3' and KnowledgeTypeId in(2,3,4)union allselect 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 allselect top(10) PaperId,CreationTime,QuestionTypeId from TB_Paper where QuestionTypeId=4 and PaperDegree ='4' and KnowledgeTypeId in(2,3,4)union allselect 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' 這樣該怎么寫呢?
查看完整描述

3 回答

?
繁星淼淼

TA貢獻(xiàn)1775條經(jīng)驗 獲得超11個贊

如果在存儲過程中使用,可以對傳入的參數(shù)使用charindex和substring函數(shù)來配合分割參數(shù),再執(zhí)行隨后的內(nèi)容

查看完整回答
反對 回復(fù) 2019-01-21
?
慕無忌1623718

TA貢獻(xiàn)1744條經(jīng)驗 獲得超4個贊

把參數(shù)分割 用while語句

?看下 sp_executesql?? 的用法

查看完整回答
反對 回復(fù) 2019-01-21
?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗 獲得超2個贊

我覺得是不是該在調(diào)用存儲過程之前就把參數(shù)確定下來呢?首先程序處理字符串應(yīng)該比較簡單而且比讓sql去處理效率來的要高吧

查看完整回答
反對 回復(fù) 2019-01-21
  • 3 回答
  • 0 關(guān)注
  • 398 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號