天天看點

SQL常用函數及語句(不斷更新)

1.申明變量:declare @index int

2.轉換函數:cast():select cast(34 as nvarchar(10))

3.替換函數:replace():replace ( orgstring/fieldname , matchstring , newstring ) 

                   參數1:待搜尋的字元串,參數2:待查找的字元串,參數3:替換後的字元串 select

replace(''abcdefghicde'',''cde'',''xxx'')

4.可空判斷:isnull(): select isnull(weight, 50) from table

5.case...end語句:

6.轉義字元:

    ①預設情況下, '是字元串的邊界符, 如果在字元串中包含', 則必須使用兩個', 第1個'就是轉義符

    ②當set quoted_identifier off時, "是字元串邊界符, 字元串中的"必須用兩個"表示。