选择列与谓词匹配的行或具有空值并替换空值。

时间:2015-11-17 20:54:05

标签: sql-server tsql

我正在尝试从表中检索“Test1”和“Test2”中列值的行,并检索“找不到值”的NULL值。以下查询无效。请告诉我。

SELECT address_id, ISNULL(city, 'No value found') AS city from 
Address where city in ('Test1', 'Test2')

2 个答案:

答案 0 :(得分:2)

不确定你的意思,但也许这会有所帮助:

SELECT address_id, ISNULL(city, 'No value found') AS city
FROM Address
WHERE ((city is null) or (city in ('Test1','Test2'));

答案 1 :(得分:0)

您的问题是,City与您的谓词不匹配。您到选择部分的happens before。请尝试

SELECT address_id, ISNULL(city, 'No value found') AS city from 
Address where city is null or city in ('Test1', 'Test2')