我有一个表tblConsentQuestion
,上面有问题
intID nvcText bitActive
17 Question1 True
18 Question2 True
19 Question3 False
和表格tblConsentData
,其中包含每个客户的问题
intID intCustomerID bitConsent intIDQuestion
14 1 False 19
15 1 True 18
WHERE tblConsentQuestion.intID = tblConsentData.intIDQuestion
我想在VB.net数据集中进行检索:
所有tblConsentData
都是特定客户的,即两个记录分别为intID = 14
和15
bitActive = true
tblConsentQuestion
中的所有活动(WHERE
tblConsentData.intIDQuestion <> tblConsentQuestion.intID
)记录,在这种情况下,只有intID = 17
条记录(除了两条记录)
输出应为:
Question3 False
Question2 True
Question1 Null
我尝试过类似的事情:
str = "Select tblConsentQuestion.intID, bitConsent, nvcText" & fungGetLangId() & " AS nvcqText " _
& " From tblConsentData " _
& " Left OUTER JOIN tblConsentQuestion " _
& " On tblConsentData.intIDQuestion = tblConsentQuestion.intID " _
& " where tblConsentData.intCustomerID = " & intCustomerID & " " _
& " UNION ALL " _
& " Select tblConsentQuestion.intID, -1, nvcText" & fungGetLangId() & " " _
& " From tblConsentQuestion " _
& " Left OUTER JOIN tblConsentData " _
& " On tblConsentData.intIDQuestion = tblConsentQuestion.intID " _
& " WHERE(tblConsentQuestion.bitActive = 'True') "
我收到了tblConsentQuestion
中的所有活动记录,而我不应该收到intID = 18
中存在的tblConsentData
的记录。
答案 0 :(得分:0)
bitActive
的数据类型是什么?它是具有两个可能的字符串的文本字段:'True'
和'False'
吗?还是“访问是/否”字段?
如果是后者,则您的SQL不应检查字符串值,而应检查True
/ False
常量(假设`fungGetLangId:
WHERE tblConsentQuestion.bitActive = True
或者,更好的是,您可以直接检查是/否字段:
WHERE tblConsentQuestion.bitActive