访问SELECT语句和硬编码值

时间:2015-01-07 15:29:50

标签: ms-access select hardcode

这是我的VB SQL语句,它应用于Form_Current上未绑定列表框的rowsource:

SelectionSQL = "SELECT tbl_Patches_Cisco_SAs_Applicability.PatchID, tbl_Patches_Cisco_SAs_Applicability.OS 
      FROM tbl_Patches_Cisco_SAs_Applicability 
      WHERE (((tbl_Patches_Cisco_SAs_Applicability.PatchID)=[Forms]![Patch_Management_Cisco_Stage2]![Publication_ID]));"

效果很好,唯一的问题是我希望rowsource包含" NA"的硬编码值,而不必创建关联的记录。这可能吗?怎么样?即以某种方式将NA添加到rowsource?

2 个答案:

答案 0 :(得分:2)

您可以使用UNION查询,该查询会为您现有的内容添加一行伪造值。

SELECT a.PatchID, a.OS
FROM tbl_Patches_Cisco_SAs_Applicability AS a
WHERE a.PatchID=[Forms]![Patch_Management_Cisco_Stage2]![Publication_ID]
UNION ALL
SELECT 0 AS PatchID, 'NA' AS OS
FROM Dual;

Dual 可以是任何只返回一行的表或查询。我为此目的使用自定义表:CreateDualTable()

答案 1 :(得分:0)

一种可能性是使用UNION查询:

SelectionSQL = "SELECT tbl_Patches_Cisco_SAs_Applicability.PatchID,
    tbl_Patches_Cisco_SAs_Applicability.OS FROM tbl_Patches_Cisco_SAs_Applicability WHERE
    (((tbl_Patches_Cisco_SAs_Applicability.PatchID)=[Forms]![Patch_Management_Cisco_Stage2]![Publication_ID])) 
    UNION SELECT TOP 1 0, 'NA' FROM tbl_Patches_Cisco_SAs_Applicability"