sql - Access Query Syntax -


i converting sql based query access runs on sql server. have converted access compatible format, except there problem in putting number of brackets. got following error "syntax error in clause", please help

select cint(mid(tc2.childcounter, 7, len(tc2.childcounter)) ) pkchildid ,tc2.visittype     ,max(iif( tktresults.taskcounter in ( '001410' ,'001463' ,'001431' ),  tktresults.result, null) ) kwa_quitoffered     ,max(iif( tktresults.taskcounter in ( '001411' ,'001464' ,'001432' ),   tktresults.result, null) ) kwa_quitreferral ((tblconsultations tc2 inner join tblchild tc    on tc2.childcounter = tc.childcounter) left  join tbldelivery td    on td.childcounter = tc.childcounter) left join ( select ttr.resultcounter     ,ttr.childcounter     ,tkt.visittype     ,ttr.result     ,ttr.taskcounter tbltaskresults ttr left join tlkpkeytasks tkt on tkt.taskcounter = ttr.taskcounter     , tkt.taskcounter in (         '001410'         ,'001463'         ,'001431'         ,'001411'         ,'001464'         ,'001432'         ) ) tktresults      on tc2.visittype = tktresults.visittype , tktresults.childcounter = tc2.childcounter tc2.visittype in (1, 2, 3, 4)    , tc2.consdate > '20130127' , tc2.consdate < '20130228' group cint(mid(tc2.childcounter, 7, len(tc2.childcounter)))                                             ,tc2.visittype                                             ,tc.centrecode                                             ,tc2.centrecode                                             ,tc2.councilcode                                             ,tc2.consdate                                             ,tc.feeding3months                                             ,tc.feeding6months                                             ,tc.feeding12months                                             ,tc2.weight                                             ,tc2.headcirc                                     order cint(mid(tc2.childcounter, 7,   len(tc2.childcounter)) ), tc2.visittype 

ms access requires parentheses around joins when have multiple tables , have unmatched parentheses causing problems. query should be:

select .... (((tblconsultations tc2 inner join tblchild tc    on tc2.childcounter = tc.childcounter) left join tbldelivery td    on td.childcounter = tc.childcounter) left join  (   select ttr.resultcounter     ,ttr.childcounter     ,tkt.visittype     ,ttr.result     ,ttr.taskcounter   tbltaskresults ttr   left join tlkpkeytasks tkt      on tkt.taskcounter = ttr.taskcounter     , tkt.taskcounter in ('001410','001463'                             ,'001431','001411'                             ,'001464','001432') ) tktresults    on tc2.visittype = tktresults.visittype   , tktresults.childcounter = tc2.childcounter) ..... 

as suggested in last comment should create , save separate query subquery , join on that. subquery can called whatever, example call myquery:

  select ttr.resultcounter     ,ttr.childcounter     ,tkt.visittype     ,ttr.result     ,ttr.taskcounter   tbltaskresults ttr   left join tlkpkeytasks tkt      on tkt.taskcounter = ttr.taskcounter     , tkt.taskcounter in ('001410','001463'                             ,'001431','001411'                             ,'001464','001432') 

and include in join:

select .... (((tblconsultations tc2 inner join tblchild tc    on tc2.childcounter = tc.childcounter) left join tbldelivery td    on td.childcounter = tc.childcounter) left join myquery tktresults  -- name of saved query create   on tc2.visittype = tktresults.visittype   , tktresults.childcounter = tc2.childcounter) ..... 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -