SQL 中in傳入字串的處理

2021-05-23 06:36:51 字數 715 閱讀 1644

路就是把傳入的字串轉換成乙個table, 見**

declare

@temptable table

(f1 nvarchar

(20))

declare

@ch nvarchar

(20)

declare

@planningcrewids nvarchar

(200)

set @planningcrewids =

'1,2,3,4,'

while

(@planningcrewids <>'')

begin

set @ch =

left(@planningcrewids,

charindex

(','

,@planningcrewids,1)

-1)insert

@temptable values

(@ch)

set @planningcrewids =

stuff

(@planningcrewids,1,

charindex

(','

,@planningcrewids,1),'')

end

select

from candidate where idplanningcrew in(

select f1 from @temptable)

sql 傳入引數為逗號分隔的字串處理方法

寫了個儲存過程,中間用到了類似這種寫法 select from user where id in 1,2,3 其中 1,2,3 是從外面傳進來的引數,就這樣執行報錯 1,2,3 轉換為int型別出錯,因為id是int型別的 想了個比較笨的解決方法 思路 迴圈將傳進來的引數 1,2,3 分割並轉換為i...

SQL中字串處理函式

一 字元轉換函式 1 ascii 返回字元表示式最左端字元的ascii 碼值。在ascii 函式中,純數字的字串可不用 括起來,但含其它字元的字串必須用 括起來使用,否則會出錯。2 char 將ascii 碼轉換為字元。如果沒有輸入0 255 之間的ascii 碼值,char 返回null 3 lo...

sql字串處理

select 120.182296 30.263618 select substring 120.182296 30.263618 0,charindex 120.182296 30.263618 0 得到120.182296 select substring 120.182296 30.26361...