错误提示:JOIN 操作语法错误。 太折磨人了,自己写的看糊涂了!谁能帮帮我啊!
cmd.CommandText = "select a.档案编号,下次随访日期 as [随访日期],a.姓名,a.联系电话,a.管理类别," & _
"CStr(DateDiff('d', Date(), 下次随访日期)) + '天' as [距离天数],a.在册状态,a.备注信息 from ({建档信息} a RIGHT JOIN" & _
" (Select 档案编号,Max(下次随访日期) As [下次随访日期] FROM {高随访} GROUP BY 档案编号 HAVING Max(下次随访日期) <= #" & nv & "# UNION" & _
" Select 档案编号,Max(下次随访日期) As [下次随访日期] FROM {糖随访} GROUP BY 档案编号 HAVING Max(下次随访日期) <= #" & nv & "# UNION" & _
" SELECT {建档信息}.档案编号,DateAdd('d', 3, {个人信息}.出生日期) as [下次随访日期] FROM {建档信息} INNER JOIN {个人信息} ON {建档信息}.档案编号 = {个人信息}." & _
"档案编号 WHERE 管理类别 Like '%儿童%' and 停止管理原因 Is Null and NOT EXISTS (SELECT * FROM {新生儿家庭访视} WHERE {个人信息}.档案编号 = {新生儿家庭访视}.档案编号) UNION" & _
" Select a.档案编号,Max(b.下次随访日期) As [下次随访日期] From {建档信息} a INNER JOIN (Select 档案编号, 下次随访日期 FROM" & _
" {新生儿家庭访视} UNION Select 档案编号, 下次随访日期 FROM {满月} UNION Select 档案编号, 下次随访日期 FROM {三月}" & _
" UNION Select 档案编号, 下次随访日期 FROM {六月} UNION Select 档案编号, 下次随访日期 FROM {八月} UNION Select 档案编号," & _
" 下次随访日期 FROM {十二月} UNION Select 档案编号, 下次随访日期 FROM {十八月} UNION Select 档案编号, 下次随访日期 FROM" & _
" {二十四月} UNION Select 档案编号, 下次随访日期 FROM {三十月} UNION Select 档案编号, 下次随访日期 FROM {三岁} UNION Select 档案编号, 下次随访日期 FROM {三岁半} UNION Select" & _
" 档案编号, 下次随访日期 FROM {四岁} UNION Select 档案编号, 下次随访日期 FROM {五岁} UNION Select 档案编号, 下次随访日期 FROM" & _
" {六岁}) b on a.档案编号 = b.档案编号 WHERE a.管理类别 Like '%儿童%' GROUP BY a.档案编号 HAVING Max(下次随访日期)" & _
" <= #" & nv & "#) b on a.档案编号 = b.档案编号 where a.村委会名称 = '" & cwh &"' And a.停止管理原因 Is null ORDER BY b.下次随访日期) RIGHT JOIN" & _
" (SELECT {建档信息}.档案编号,{建档信息}.建档日期 as [下次随访日期] FROM {建档信息} INNER JOIN {个人信息} ON {建档信息}.档案编号 = {个人信息}." & _
"档案编号 WHERE 管理类别 Like '%孕产妇%' and 停止管理原因 Is Null and NOT EXISTS (SELECT * FROM {产前随访} WHERE {个人信息}.档案编号 = {产前随访}.档案编号) UNION" & _
" Select a.档案编号,Max(下次随访日期) As [下次随访日期] From {建档信息} a INNER JOIN (Select 档案编号,Max(下次随访日期) As [下次随访日期] FROM {产前随访} GROUP BY 档案编号 HAVING Max(下次随访日期) <= #" & nv & "# UNION" & _
" Select 档案编号,Max(下次随访日期) As [下次随访日期] FROM {第2-5次产前} GROUP BY 档案编号 HAVING Max(下次随访日期) <= #" & nv & "# UNION" & _
" Select 档案编号,Max(下次随访日期) As [下次随访日期] FROM {产后访视} GROUP BY 档案编号 HAVING Max(下次随访日期) <= #" & nv & "# ) b on a.档案编号 = b.档案编号 WHERE a.管理类别 Like '%孕产妇%' GROUP BY a.档案编号 HAVING Max(下次随访日期)" & _
" <= #" & nv & "#) c on a.档案编号 = c.档案编号 where a.村委会名称 = '" & cwh &"' And a.停止管理原因 Is null ORDER BY c.下次随访日期"