SQL Server 2008 および SQL Server 2008 R2 の不具合修正情報の公開 – 照合順序のバージョンが 90 の場合、誤った実行結果が返ってくる事象について

山崎 実久 
SQL Engine Support Engineer

下記の SQL Server のバージョンで修正済みですが、マイクロソフト サポート技術記事で公開されていない不具合情報を記載します。

・SQL Server 2008 SP2 Cumulative Update 7
・SQL Server 2008 R2 Cumulative Update 11
・SQL Server 2008 R2 SP1 Cumulative Update 4

上記の環境より前のバージョンをご利用で、データベースの照合順序のバージョンが 90 の場合、LIKE 句を含み % のワイルドカード文字を利用するクエリを実行した際、誤った結果が返ってくる事象が報告されています。
もしくは、以下のように照合順序のバージョンを 90 を利用してクエリを実行した場合、誤った結果が返ってくる事象が報告されています。

Select * from table where c1 like '1%5' collate Japanese_90_CI_AS

以下に、本不具合を再現可能なサンプルスクリプトの例を紹介します。

-- データベース作成
create database TEST1111

-- テーブル作成
use TEST1111
go
create table repro_table(c1 varchar(100))
go

-- レコードの登録
insert into repro_table values('10000031')
insert into repro_table values('10000051')
insert into repro_table values('10005001')
insert into repro_table values('10000032')
insert into repro_table values('10000052')
insert into repro_table values('10005002')
insert into repro_table values('10000033')
insert into repro_table values('10000053')
insert into repro_table values('10005003')
insert into repro_table values('10000034')
insert into repro_table values('10000054')
insert into repro_table values('10005004')
insert into repro_table values('10000035')
insert into repro_table values('10000055')
insert into repro_table values('10005005')
insert into repro_table values('10000036')
insert into repro_table values('10000056')
insert into repro_table values('10005006')
insert into repro_table values('10000037')
insert into repro_table values('10000057')
insert into repro_table values('10005007')
insert into repro_table values('10000038')
insert into repro_table values('10000058')
insert into repro_table values('10005008')
insert into repro_table values('10000039')
insert into repro_table values('10000059')
insert into repro_table values('10005009')
insert into repro_table values('10000030')
insert into repro_table values('10000050')
insert into repro_table values('10005000')

--照合順序  Japanese_CI_AS を利用しクエリ実行
select * from repro_table where c1 like '1%5' collate Japanese_CI_AS
go

(クエリの実行結果) 3 件のレコードが返ってきます。 これは正しい動作です。

Japanese_CI_AS

-- 照合順序 Japanese_90_CI_AS を利用しクエリ実行
select * from repro_table where c1 like '1%5' collate Japanese_90_CI_AS
go

(クエリの実行結果) 3 件のレコードが返ってくることが期待されるが、1 件のレコードしか返ってきません。 これは本不具合に該当します。

Japanese_90_CI_AS

上記の不具合の修正を含むバージョンについては、以下の技術情報に記載がございます。

Cumulative update package 7 for SQL Server 2008 Service Pack 2
https://support.microsoft.com/kb/2617148

Cumulative Update package 11 for SQL Server 2008 R2
https://support.microsoft.com/kb/2633145

Cumulative update package 4 for SQL Server 2008 R2 Service Pack 1
https://support.microsoft.com/kb/2633146

+ 参考情報
現在お客様がご利用の SQL Server のバージョンを確認する方法は下記技術情報に詳細が記載されております。

SQL Server のバージョンとエディションを識別する方法
https://support.microsoft.com/kb/321185