sql中charindex和cast結合使用

2022-02-09 19:19:56 字數 658 閱讀 2990

1.charindex函式常常用來在一段字元中搜尋字元或者字串。

語法

charindex ( expression1 , expression2 [ ,

start_location ] )

返回的值是:返回字串中指定表示式(expression1)的起始位置。

那些什麼定義啊,什麼的我就不講了,直接用列子來講,這樣大家理解的比較透徹點。

set_user表中userid,而userid存的是乙個集合,每個userid是以「,」間隔,類似於這樣「1,2,3」。現在我要查詢userid為21的使用者,我們可以這樣寫

select * from set_user where (charindex(','+cast('" + userid + "'

as nvarchar(10))+',', ','+cast(userid as nvarchar(10))+',') >0

)上面這段sql語句中有個cast函式

將某種資料型別的表示式顯式轉換為另一種資料型別。

語法:cast ( expression as data_type )

cast(ytd_sales as char(20))

sql中的CHARINDEX和臨時表

update temp set temp.recycle case when uniona.num 0 then 1 else 0 end from select gradeid,sum num as num from areaallot where charindex area,areaallot...

C 中的ref和out與SQL中的output

有時,我們會需要獲取某個值在方法中的執行狀態,根據定義的方法,我們僅僅能夠獲得乙個返回值,但是,有時我們也許想獲取多個值,通過返回值就不能返回這樣的資訊,我們可以通過在引數前使用ref或out,以得到多個返回值.在執行sql儲存過程時,我們可以通過sql語句在儲存過程中的執行狀態,返回相應的值.sq...

c 中 執行SQL語句

網上看的 刪除一行資料,雖然下面兩個寫法都能實現,但是都有問題。void c資料庫測試dlg onbnclickeddelbtn cstring str m listctrl.getitemtext index,1 strsql.format t delete from customertype w...