An expression from a single query pulled into a subsequent query

I have the following tables "Base" and "Join":

Base:
ID  Field
A   1
B   2
D   

Join:
ID
A
B
C
D

I use the following query to select "ExampleQuery" to parse "Base":

SELECT Base.ID, IIf(IsNull([Field]),"None",[Field]) AS Newfield
FROM Base;

And the following select query to the left-join table "Join" for the query "ExampleQuery":

SELECT Join.ID, ExampleQuery.Newfield
FROM [Join] LEFT JOIN ExampleQuery ON Join.ID = ExampleQuery.ID;

My conclusion is as follows:

ID  Newfield
A   1
B   2
C   None
D   None

I expect the value of C to be null since it was not in the ExampleQuery output, however, it uses the logic from the expression in the original query instead. Why is this happening, and how can I prevent it? I want to process my initial select query strictly as a temporary table.

+1
source share
3 answers

, Base None:

SELECT t1.ID, t2.Newfield
FROM [Join] t1
LEFT JOIN
(
    SELECT ID, IIF(ISNULL([Field]),"None", [Field]) AS Newfield
    FROM Base
) t2
    ON t1.ID = t2.ID;

, JOIN Access (, , SQL). , .. .

+1

, null: , , NULL, , .

, , , . , , , , . Access , ,

ID  NewField
A   1
B   2
D   None

, , Query1. Query1 (Access , ), .

0

, . "ExampleQuery" :

SELECT Base.ID, IIf(IsNull([Field]) And Not IsNull([ID]),"None",[Field]) AS Newfield
FROM Base;

, , "ExampleQuery", "Join":

ID  Newfield
A   1
B   2
C   
D   None
0

Source: https://habr.com/ru/post/1692017/


All Articles