OVH Cloud OVH Cloud

Bug ?

4 réponses
Avatar
Fred BROUARD
Le contexte :
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

Le test :

SET ANSI_DEFAULTS ON

CREATE TABLE TX
(COL11 INT,
COL21 INT)

INSERT INTO TX VALUES (101, NULL)
INSERT INTO TX VALUES (102, 101)

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX)

Le résultat :

COL11 COL21
----------- -----------

(0 ligne(s) affectée(s))


???

Apparament, c'est la gestion du NULL par SQL Server qui pose problème :

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX
WHERE COL21 IS NOT NULL)

COL11 COL21
----------- -----------
102 101

!!!

Qui a des explications ?


--
Frédéric BROUARD, MVP SQL Server. Expert SQL / spécialiste Delphi, web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************

4 réponses

Avatar
bruno reiter [MVP]
quand tu mets SET ANSI_DEFAULTS ON, cela met ANSI_NULLS ON, donc les
comparaisons à null donnent null, comme tu as un null dans le IN, il n'y a
aucune égalité donc un jeu de résultats vide.

si tu positionnes ANSI_NULLS OFF, tu auras un résultat dans ton premier
SELECT

br

"Fred BROUARD" wrote in message
news:
Le contexte :
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

Le test :

SET ANSI_DEFAULTS ON

CREATE TABLE TX
(COL11 INT,
COL21 INT)

INSERT INTO TX VALUES (101, NULL)
INSERT INTO TX VALUES (102, 101)

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX)

Le résultat :

COL11 COL21
----------- -----------

(0 ligne(s) affectée(s))


???

Apparament, c'est la gestion du NULL par SQL Server qui pose problème :

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX
WHERE COL21 IS NOT NULL)

COL11 COL21
----------- -----------
102 101

!!!

Qui a des explications ?


--
Frédéric BROUARD, MVP SQL Server. Expert SQL / spécialiste Delphi, web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************



Avatar
Thierry
Bonjour,

Essayer avec : SET ANSI_NULLS OFF, le comportement sera diffèrent.

autre exemples :

select * from tx where col11 not in (null)
select * from tx where col11 <> null

J'ai effectué ce test avec un autre moteur de base de données (Visual
Foxpro), c'est exactement pareil qu'avec SQL Server. Est-ce la norme ANSI
SQL qui dicte celà ?


--
Thierry


"Fred BROUARD" a écrit dans le message de news:

Le contexte :
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

Le test :

SET ANSI_DEFAULTS ON

CREATE TABLE TX
(COL11 INT,
COL21 INT)

INSERT INTO TX VALUES (101, NULL)
INSERT INTO TX VALUES (102, 101)

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX)

Le résultat :

COL11 COL21
----------- -----------

(0 ligne(s) affectée(s))


???

Apparament, c'est la gestion du NULL par SQL Server qui pose problème :

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX
WHERE COL21 IS NOT NULL)

COL11 COL21
----------- -----------
102 101

!!!

Qui a des explications ?


--
Frédéric BROUARD, MVP SQL Server. Expert SQL / spécialiste Delphi, web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************



Avatar
Fred BROUARD
Effectivement, c'est dans la norme SQL !

"
If any argument is NULL, the <in predicate> return UNKNOWN
"

C'est d'ailleurs sémantiquement le même comportement que = ANY

SELECT *
FROM TX
WHERE NOT COL11 = ANY (SELECT COL21
FROM TX)

Dans les deux cas, il faut denullifier :

SELECT *
FROM TX
WHERE NOT COL11 = ANY (SELECT COL21
FROM TX
WHERE COL21 IS NOT NULL)

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX
WHERE COL21 IS NOT NULL)


bruno reiter [MVP] a écrit:
quand tu mets SET ANSI_DEFAULTS ON, cela met ANSI_NULLS ON, donc les
comparaisons à null donnent null, comme tu as un null dans le IN, il n'y a
aucune égalité donc un jeu de résultats vide.

si tu positionnes ANSI_NULLS OFF, tu auras un résultat dans ton premier
SELECT

br

"Fred BROUARD" wrote in message
news:

Le contexte :
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

Le test :

SET ANSI_DEFAULTS ON

CREATE TABLE TX
(COL11 INT,
COL21 INT)

INSERT INTO TX VALUES (101, NULL)
INSERT INTO TX VALUES (102, 101)

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX)

Le résultat :

COL11 COL21
----------- -----------

(0 ligne(s) affectée(s))


???

Apparament, c'est la gestion du NULL par SQL Server qui pose problème :

SELECT *
FROM TX
WHERE COL11 NOT IN (SELECT COL21
FROM TX
WHERE COL21 IS NOT NULL)

COL11 COL21
----------- -----------
102 101

!!!

Qui a des explications ?


--
Frédéric BROUARD, MVP SQL Server. Expert SQL / spécialiste Delphi, web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************









--
Frédéric BROUARD, MVP SQL Server. Expert SQL / spécialiste Delphi, web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************
Avatar
Philippe T [MS]
Bonjour,

Comme l'a indiqué Fred, c'est bien dans la norme !!!

Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"Thierry" wrote in message
news:
Bonjour,

Essayer avec : SET ANSI_NULLS OFF, le comportement sera diffèrent.

autre exemples :

select * from tx where col11 not in (null)
select * from tx where col11 <> null

J'ai effectué ce test avec un autre moteur de base de données (Visual
Foxpro), c'est exactement pareil qu'avec SQL Server. Est-ce la norme ANSI
SQL qui dicte celà ?


--
Thierry


"Fred BROUARD" a écrit dans le message de


news:

> Le contexte :
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Dec 17 2002 14:22:05
> Copyright (c) 1988-2003 Microsoft Corporation
> Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
>
> Le test :
>
> SET ANSI_DEFAULTS ON
>
> CREATE TABLE TX
> (COL11 INT,
> COL21 INT)
>
> INSERT INTO TX VALUES (101, NULL)
> INSERT INTO TX VALUES (102, 101)
>
> SELECT *
> FROM TX
> WHERE COL11 NOT IN (SELECT COL21
> FROM TX)
>
> Le résultat :
>
> COL11 COL21
> ----------- -----------
>
> (0 ligne(s) affectée(s))
>
>
> ???
>
> Apparament, c'est la gestion du NULL par SQL Server qui pose problème :
>
> SELECT *
> FROM TX
> WHERE COL11 NOT IN (SELECT COL21
> FROM TX
> WHERE COL21 IS NOT NULL)
>
> COL11 COL21
> ----------- -----------
> 102 101
>
> !!!
>
> Qui a des explications ?
>
>
> --
> Frédéric BROUARD, MVP SQL Server. Expert SQL / spécialiste Delphi, web
> Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
> Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
> ************************ www.datasapiens.com *************************
>