トップページに戻る    次のSQLServerのサンプルへ    前のSQLServerのサンプルへ

1-3 文字列関数(文字列の検索)


select
case when 'abc' Like '[a-z][a-z][a-z]' then 1 else 0 end as chk1,
case when 'abc' Like '[a-z][a-z]' then 1 else 0 end as chk2,
case when 'abc' Like '%[a-z]%' then 1 else 0 end as chk3,
case when 'abc' Like '%[^a-z]%' then 1 else 0 end as chk4,
case when 'abc' Like '%[^0-9]%' then 1 else 0 end as chk5
go

chk1  chk2  chk3  chk4  chk5
----  ----  ----  ----  ----
   1     0     1     0     1

MSDN --- Like述語


select
CharIndex('b','abc') as "CharIndex関数1",
CharIndex('X','abc') as "CharIndex関数2"
go

CharIndex関数1  CharIndex関数2
--------------  --------------
             2               0

MSDN --- CharIndex


select
PatIndex('%[a-z][a-z]%','1a2a3abc') as "PatIndex関数1",
PatIndex('%[^0-9]%','1a2a3abc') as "PatIndex関数2"
go

PatIndex関数1  PatIndex関数2
-------------  -------------
            6              2

MSDN --- PatIndex