Results 1 to 3 of 3

Thread: [RESOLVED] Translating Oracle SQL to MS Access SQL

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Resolved [RESOLVED] Translating Oracle SQL to MS Access SQL

    I never learned SQL too well. A friend (who only uses Oracle) wrote some SQL for me, and I'm trying to translate it for MS Access. The SQL is:

    SELECT a.id,
    case when b.ufa is null then c.ufa
    else b.ufa end as ufa
    FROM metrotmp a,
    (select mt.ID,mc.GEOID,mu.UFA
    from metrotmp mt, metrocbsa mc, metroufa mu
    where mt.ZIP = mc.ZIP
    and mc.GEOID=mu.GEOID) b,
    (select mt1.id, mu1.UFA
    from metrotmp mt1, metroufa mu1
    where mt1.STATE = mu1.GEO ) c
    where a.id = b.id (+)
    and a.id = c.id


    I think there are three problems with this:

    1. Access has no "case when"
    2. Access has no "is null"
    3. Access has no "(+)".

    For #1, I think nested iif's will work.
    For #2, I think nz() will work.

    What exactly is (+)? How would I translate (+) into MS Access SQL?

    Thanks!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Translating Oracle SQL to MS Access SQL

    1. You are on the right track, IIf is the equivalent of Case - but in this situation (because the check is for Null) I think NZ would do the job on its own.

    2. Yes it does.

    3. I think that is a Left Outer Join (and I think on the condition it follows). To use it you will need to use 'modern' SQL syntax rather than specifying join details in the Where clause, eg:
    Code:
    SELECT ...
    
    FROM (metrotmp a
    LEFT OUTER JOIN (select mt.ID,mc.GEOID,mu.UFA
                     from metrotmp mt, metrocbsa mc, metroufa mu
                     where mt.ZIP = mc.ZIP
                     and mc.GEOID=mu.GEOID) b
      ON a.id = b.id)
    INNER JOIN (select mt1.id, mu1.UFA
                from metrotmp mt1, metroufa mu1
                where mt1.STATE = mu1.GEO ) c
      ON a.id = c.id
    I could be wrong as I haven't used Oracle in years, but this should at least be on the right track.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Re: Translating Oracle SQL to MS Access SQL

    Unfortunately, nz() isn't part of the Jet engine (I'm using Excel/VBA to access Access using the Jet engine). I think IIF() is required here. :-(

    A *big* thanks for the outer join thing. I never would've gotten that in a million years....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width