First of all, i do not believe you that above query works fine in MS Access, because it does contain reserved word:
type
, which is not allowed. Please, see
the list of reserved words in MS Access[
^].
To be able to use reserved word in MS Access query, you need to add
[]
brackets around reserved word:
[type]
MS Access database engine does like
;
at the end of query.
SELECT no_id, mstrid, [type], details, myob, dated
FROM (
SELECT rcptdetails.no_id, RcptMasterNo AS mstrid , [type], details, rcptmaster.myob,rcptmaster.dated
FROM rcptdetails INNER JOIN rcptmaster ON rcptmaster.no_id=rcptdetails.RcptMasterNo
union all
SELECT pymtdetails.no_id, PymtMasterNo AS mstrid , [type], details, pymtmaster.myob, pymtmaster.dated
FROM pymtdetails INNER JOIN pymtmaster ON pymtmaster.no_id=pymtdetails.PymtMasterNo
union all
SELECT pymtdetailscash.no_id, PymtMasterNo AS mstrid ,'PaymentCash' AS [type], details, pymtmastercash.myob, pymtmastercash.dated
FROM pymtdetailscash INNER JOIN pymtmastercash ON pymtmastercash.no_id=pymtdetailscash.PymtMasterNo
union all
SELECT jvdetails.noid, JVMMaster AS mstrid , jvdetails.[type], details,jvmaster.myob, jvmaster.dated
FROM jvdetails INNER JOIN jvmaster ON jvmaster.no_id=jvdetails.JVMMaster
union all
SELECT pdcidetails.no_id, PDCIMasterNo AS mstrid, pdcidetails.[type], details, pdcimaster.myob, pdcimaster.dated
FROM pdcidetails INNER JOIN pdcimaster ON pdcimaster.no_id=pdcidetails.PDCIMasterNo
union all
SELECT pdcrdetails.no_id, PDCrMasterNo AS mstrid , pdcrdetails.[type], details, pdcrmaster.myob, pdcrmaster.dated
FROM pdcrdetails INNER JOIN pdcrmaster ON pdcrmaster.no_id=pdcrdetails.PDCrMasterNo
) AS sqlmain
where 1 = 1 And Details Is Not null and Details like ?;
where
?
means parameter.
Final suggestion:
1) It is strongly recommended to ude
parameters[
^] together with OledbCommand to avoid
Sql Injection[
^].
2) If you're trying to write application which can use few data providers, i'd suggest to read this:
Writing a Portable Data Access Layer[
^]
3) Use table
aliases[
^] instead of their names