0

你能让我知道我在这个查询中遇到语法错误的地方吗?查询包含三个表,所有表都使用左连接连接在一起。请提供解决方案...

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

4

1 回答 1

0

摆脱:(as afrom CRS_BCP_Holding as a left join对不起,我误读了查询。很好AS a,下面将进一步描述警告。)

(...)
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 被解释为“2013 年 4 月 8 日” ; 而在我们的美国服务器上,它将被解释为“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
于 2013-04-08T09:32:42.187 回答