Microsoft로 로그인
로그인하거나 계정을 만듭니다.
안녕하세요.
다른 계정을 선택합니다.
계정이 여러 개 있음
로그인할 계정을 선택합니다.
영어
죄송합니다. 이 문서는 귀하의 언어로 사용할 수 없습니다.

When you run a query against a Microsoft SQL Server Compact 3.5 database, an incorrect result is returned. This issue occurs when the query contains a conjunction and a disjunction. If we assume that the operators are AND and OR, the query must meet the following specific conditions:

  • One of the operands of the AND operator is an expression that contains the OR operator.

  • The operands of the OR operator contain expressions that reference the same column. Therefore, an index of the column can be used to match the expressions.

  • The other operand of the AND operator contains a reference to a column that uses the same index as the column that is specified in the previous bullet point in this list. Therefore, the index can be also used on this expression.

For example, assume that you create the following tables that use indexes in a SQL Server Compact 3.5 database.

CREATE TABLE T1(
C1 int,
C2 int
)
GO
CREATE INDEX IND_T1 ON T1 (C1, C2)
GO
CREATE TABLE T2(
C1 int,
C2 int
)
GO
CREATE INDEX IND_T2 ON T2 (C1, C2)
GO
INSERT INTO T1 VALUES (1, 0)
GO
INSERT INTO T1 VALUES (2, 0)
GO
INSERT INTO T2 VALUES (1, -1)
GO
INSERT INTO T2 VALUES (2, 0)
GO

Then, you run the following query:

SELECT T1.C1 [T1.C1], T1.C2 [T1.C2], T2.C1 [T2.C1], T2.C2 [T2.C2]
FROM T1 INNER JOIN T2 ON
T1.C1 = T2.C1
AND (T1.C2 = T2.C2 OR T2.C2 = -1)
GO

After you run the query, you receive the following incorrect result:

T1.C1

T1.C2

T2.C1

T2.C2

2

0

2

0

However, you expect the following result:

T1.C1

T1.C2

T2.C1

T2.C2

1

0

1

-1

2

0

2

0

Note This issue also occurs when you use the WHERE clause to perform a logical conjunction on two expressions. For example, this issue also occurs when you run the following query:

SELECT T1.C1 [T1.C1], T1.C2 [T1.C2], T2.C1 [T2.C1], T2.C2 [T2.C2]
FROM T1 INNER JOIN T2 ON
T1.C1 = T2.C1
WHERE T1.C2 = T2.C2 OR T2.C2 = -1
GO

Symptoms

The hotfix that resolves this issue is included in cumulative update package 4 for SQL Server Compact 3.5 Service Pack 2.

For more information about how to obtain cumulative update package 4 for SQL Server Compact 3.5 Service Pack 2, click the following article number to view the article in the Microsoft Knowledge Base:

2516828 Cumulative Update 4 for SQL Server Compact 3.5 Service Pack 2

Resolution

To work around this issue, rewrite the query by using one of the following methods:

Method 1

Use table hints in the query to disable the indexes. For example, run the following query to disable the indexes:

SELECT T1.C1 [T1.C1], T1.C2 [T1.C2], T2.C1 [T2.C1], T2.C2 [T2.C2]
FROM T1 INNER JOIN T2 WITH (INDEX(0)) ON
T1.C1 = T2.C1
AND (T1.C2 = T2.C2 OR T2.C2 = -1)
GO

Method 2

Re-write the query to avoid meeting the conditions that are mentioned in the "Symptoms" section:

SELECT T1.C1 [T1.C1], T1.C2 [T1.C2], T2.C1 [T2.C1], T2.C2 [T2.C2]
FROM T1 INNER JOIN T2 ON
(T1.C1 = T2.C1 AND T2.C2 = -1) OR (T1.C1 = T2.C1 AND T1.C2 = T2.C2)

Workaround

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Status

도움이 더 필요하세요?

더 많은 옵션을 원하세요?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

이 정보가 유용한가요?

사용 경험에 어떠한 영향을 주었나요?
제출을 누르면 피드백이 Microsoft 제품과 서비스를 개선하는 데 사용됩니다. IT 관리자는 이 데이터를 수집할 수 있습니다. 개인정보처리방침

의견 주셔서 감사합니다!

×