你可以让我知道我在这个查询中遇到语法错误的地方......查询包含三个表,并且所有表都使用left join.Plz连接在一起提供解决方案......
select a.ACNo as CLIENTACCOUNTNO,
b.CLIentSHoRTCoDE as CLIENTCODE,
a.Client as CLIENTNAME,
a.SECURITY_TYPE as SECURITYTYPE,
c.SECMSECNO as SCRIPCODE,
a.EXCE as EXCH,
a.SEC_IDENT as SECIDENT,
a.SECURITY_NAME as SECURITYNAME,
a.INST_TYPE as INSTTYPE,
a.SECURITY_CCY as SECURITYCC,
a.SECURITY_PRICE as SECURITYPRICE,
a.PRICE_DATE as PRICEDATE,
a.LOCATION as LOCATION,
a.LOCATION_STATUS as LOCATIONSTATUS,
a.HOLDINGS as HOLDINGS,
a.UNITS as UNITS,
a.SALEABLE_STOCK as SALEABLESTOCK,
a.FACE_VALUE as FACEVALUE,
a.CCY_PORTFOLIO_VALUE as CCYPORTFOLIOVALUE,
a.PORTFOLIO_VALUE_ININR as PORTFOLIOVALUE,
a.MATURITY_DATE as MATURITYDATE,
a.PREV_COUPON_DATE as PREVCOUPONDATE,
a.NEXT_COUPON_DATE as NEXTCOUPONDATE,
a.OPTION_DATE as OPTIONDATE,
a.DEADLINE_DATE as DEADLINEDATE,
a.EVENT_TYPE as EVENTTYPE
from CRS_BCP_Holding as a left join
AccountMaster as b on Cint(a.acno) =b.CashAcNo left join InstrumentMaster as c on
a.SEC_IDENT=c.ISIN and c.status<>'c' and c.bse_Code='b'
where ((a.OPTION_DATE between 8/04/2013 and 8/04/2013 ) and (a.LOCATION_STATUS='Surrendered for CA' OR a.EVENT_TYPE='PART'))
order by b.CLIentSHoRTCoDE,c.SECMSECNO,a.LOCATION,a.LOCATION_STATUS
此查询用于Access 2007
答案 0 :(得分:0)
摆脱(抱歉,我误读了查询。as a
中的from CRS_BCP_Holding as a left join
:AS a
很好,下面将进一步说明。)< / p>
(...)
FROM CRS_BCP_Holding AS a
LEFT JOIN AccountMaster AS b
ON CInt(a.acno) = b.CashAcNo
LEFT JOIN InstrumentMaster as c
ON (...)
另外,如果你真的需要使用缩写,我会使用更有意义的缩写(例如'cbh'代表'CRS_BCP_Holding','am'代表'AccountMaster'等等)使用'a ','b','c'表示任何表都很难读取列引用的内容。
此外,就像Santosh在评论中所说,VBA使用哈希来指定日期文字:
WHERE ((a.OPTION_DATE BETWEEN #2013-04-08# and #2013-04-08#) ...)
(我还使用ISO标准日期格式格式化日期,以确保正确解释日期,无论系统的区域设置如何。在我的(荷兰)机器上,8/04/2013被解释为'8 2013年4月';而在我们的美国服务器上,它将被解释为'2013年8月4日'。另一方面,2013-04-08是明确的。
把所有东西放在一起,以下工作吗?
SELECT a.acno AS clientaccountno
, b.clientshortcode AS clientcode
, a.client AS clientname
, a.security_type AS securitytype
, c.secmsecno AS scripcode
, a.exce AS exch
, a.sec_ident AS secident
, a.security_name AS securityname
, a.inst_type AS insttype
, a.security_ccy AS securitycc
, a.security_price AS securityprice
, a.price_date AS pricedate
, a.location AS location
, a.location_status AS locationstatus
, a.holdings AS holdings
, a.units AS units
, a.saleable_stock AS saleablestock
, a.face_value AS facevalue
, a.ccy_portfolio_value AS ccyportfoliovalue
, a.portfolio_value_ininr AS portfoliovalue
, a.maturity_date AS maturitydate
, a.prev_coupon_date AS prevcoupondate
, a.next_coupon_date AS nextcoupondate
, a.option_date AS optiondate
, a.deadline_date AS deadlinedate
, a.event_type AS eventtype
FROM crs_bcp_holding AS a
LEFT JOIN AccountMaster AS b
ON CInt(a.acno) = b.cashacno
LEFT JOIN InstrumentMaster AS c
ON a.sec_ident = c.isin
AND c.status <> 'c'
AND c.bse_Code = 'b'
WHERE (a.option_date BETWEEN #2013-04-08# AND #2013-04-08#)
AND (a.location_status = 'Surrendered for CA' OR a.event_type = 'PART')
ORDER BY b.clientshortcode
, c.secmsecno
, a.location
, a.location_status