簡體   English   中英

在訪問查詢中需要幫助

[英]Need help in access query

我對訪問查詢有疑問...

請告知是否可能

我已將excel文件鏈接到access中,它具有一些列..我的問題是

例如

要從筆記本電腦,台式機表中檢索描述和“區域”列

我確實使用以下查詢

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

有時..它可能不包含“區域”字段,那時候我確實使用“”作為筆記本電腦。[區域]或“”作為桌面。[區域]

我的追求是

有沒有這樣的選擇

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

我假設您在偽代碼中提到“ = available”表示存在值。 您只想處理一個空值。

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

NZ()函數將處理空值並替換您想要的任何值。

您可以在此查詢中使用切換用例,但在mS-acess中不支持,但在訪問中進行切換的另一種方式是使用iif(),這里我為您提供了一個通用示例,您可以在實際查詢中輕松地將其轉換。

IIf(expr, truepart, falsepart)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM