我正在努力弄清楚如何将 T-SQL 查询转换为 MSAccess 将执行的格式。我对 MSAccess 很陌生,所以这就是我的周末。我正在尝试获取将我想要的信息拉入 MSAccess 的查询:
SELECT p.person_id, mem.profile_id, nick_name, last_name, p.postal_code,p.birth_date,p.gender, grade.selected_value
FROM dbo.core_profile_member AS mem
INNER JOIN dbo.core_person AS p ON mem.person_id = p.person_id
LEFT JOIN dbo.evnt_registrant_field AS grade ON mem.person_id = grade.person_id AND mem.profile_id = grade.profile_id AND grade.custom_field_id=@gradeID
WHERE mem.status_luid <> 316 AND mem.profile_id IN (@profiles)
我一直在努力解决这个问题,阅读各种帖子,试图弄清楚如何让它发挥作用。到目前为止,这是我想出的,但是当代码执行查询时会引发语法错误。这是我到目前为止不起作用的内容:
strSQL1 =
"SELECT p.person_id, mem.profile_id, nick_name, last_name, " & _
" p.postal_code, p.birth_date, p.gender FROM (" & _
" dbo_core_profile_member AS mem INNER JOIN dbo_core_person AS p ON mem.person_id = p.person_id " & _
" LEFT JOIN (SELECT person_id, profile_id, selected_value FROM dbo_evnt_registrant_field " & _
" WHERE custom_field_id = " & strGradeID & ") AS grade ON mem.person_id = grade.person_id " & _
" AND mem.profile_id = grade.profile_id) " & _
" WHERE mem.status_luid <> 316 AND mem.profile_id IN (" & strProfileIDs & ");"
我知道变量工作正常。如果我在创建该字符串后调试并检查立即窗口,我实际上可以在 MSSQL 管理工作室中运行它并且它工作正常。我确定我错过了 SQL 生成器不喜欢的一些细微的 MSAccess 细微差别。
有人对我需要解决的问题有意见吗?使用上面的代码,我收到“查询表达式中的语法错误(缺少运算符)......”错误。