开发者

Access query with no returned results

I have a query in Access and would like to k开发者_如何转开发now if it were possible to use the where not exists clause to display a specific text for each field when there are no returned rows.

Example query:

Select Field1, Field2, Field3  
From TableA  
Where Field1 = "test";

If there are no returned results I would like the following to return:

Field1 = "test"  
Field2 = "not provided"  
Field2 = "not provided"  


How about:

SELECT Field1, Field2
FROM Table
WHERE ID=3
UNION ALL SELECT DISTINCT "None","None" FROM AnyTableithAtLeastOneRow
WHERE 3 NOT IN (SELECT ID FROM Table)


The usual way to do what you're asking is:

Select Field1, isnull(Field2, 'Not Provided'), isnull(Field3, 'Not Provided')

edit whoops, you're using Access, in that case the equivalent function is "nz" (what?! :p)

Select Field1, nz(Field2, 'Not Provided'), nz(Field3, 'Not Provided')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜