在访问查询中需要帮助

时间:2012-02-15 09:11:28

标签: sql ms-access excel-2007 ms-access-2007

我对访问查询有疑问......

请建议是否可能

我已将excel文件链接到access,它有一些列..我的问题是

对于E.g

从笔记本电脑,桌面表

中检索说明和区域列

我确实使用以下查询

SELECT Laptop.[Description], Laptop.[Region] From Laptop 
union SELECT Desktop.[Description], Desktop.[Region] From Desktop

有时..它可能不包含Region字段,在那段时间我使用“”作为Laptop。[Region]或“”作为Desktop。[Region]

我的任务是

有没有像这样的选项

SELECT Laptop.[Description], If Laptop.[Region]=avairable 
     then Laptop.[Region] else “” as [Region] from Laptop; 

或以任何方式跳过错误...

请帮助我......提前THx

的疑问:

要清楚

如果桌面表有描述和区域列..

Description Region
Saran       east
Sathish     north 
sathy       west

笔记本电脑有桌面表有说明和费用......

Description  Cost
asdf         23
dkasfjasd    34
flkasdf      55
Select Laptop.[Description], NZ(Laptop.[Region], "NA") as [Region] 
from Laptop 
UNION 
SELECT Desktop.[Description], NZ(Desktop.[Region], "NA") as [Region] 
FROM Desktop;

它会返回此结果吗?

我无法运行,因为我遇到了一些访问问题

Description  Region
asdf              
dkasfjasd   
flkasdf 
Saran        east
Sathish      north 
sathy        west

2 个答案:

答案 0 :(得分:3)

我假设您使用的伪代码可以使用“#av; = avarable'表示存在一个值。你只想处理一个空值。

Select Laptop.Description, NZ(Laptop.Region, "") as [Region] from Laptop;

NZ() function将处理空值并替换您想要的任何内容。

答案 1 :(得分:1)

你可以在这个查询中使用switch case但是在mS-acess中它不受支持但是在访问中使用的另一种方法是使用iif()这里我给你一个通用的例子你可以轻松地在你的转换中实际查询。

IIf(expr, truepart, falsepart)

 SELECT  IIF(IsNull(Laptop.[Region])," ",Laptop.[Region]) as region
FROM Laptop ;
相关问题