?
Solved

please fix an oracle query

Posted on 2014-01-31
5
Medium Priority
?
328 Views
Last Modified: 2014-02-06
Hi,

I can't run the following SQL, could you please fix this

thanks
-anshu


sql error--------------------------------------------

SELECT mt1.em_user_abbrev,
       rp2.is_rep_name,
       ur3.em_user_abbrev,
       SUM(EXEC)
FROM   (SELECT c.em_user_abbrev,
               a.em_user_id,
               c.is_rep_id,
               Count(DISTINCT a.is_doc_job_id) EXEC
        FROM   mstr_em_wh_stats.is_doc_fact a
               join mstr_em_wh_stats.is_rep_doc b
                 ON ( a.is_doc_id = b.is_doc_id )
               join (SELECT is_rep_id,
                            em_user_abbrev
                     FROM   mstr_em_wh_stats.is_rep_fact
                            join mstr_em_wh_stats.em_user
                              ON ( is_rep_fact.em_user_id = em_user.em_user_id )
                     WHERE  day_id between'20130828'and'20131028'
                            AND (Lower(em_user_abbrev) LIKE'%mstr%'OR
                                 Lower(em_user_abbrev) = 'administrator')
                     GROUP  BY is_rep_id,
                               em_user_abbrev) c
                 ON ( b.is_rep_id = c.is_rep_id )
        WHERE  a.day_id between'20130828'and'20131028'
        GROUP  BY c.em_user_abbrev,
                  a.em_user_id,
                  c.is_rep_id
        UNIONALL
        SELECT c.em_user_abbrev,
               a.em_user_id,
               c.is_rep_id,
               Count(DISTINCT a.is_rep_job_id) EXEC
        FROM   mstr_em_wh_stats.is_rep_fact a
               join mstr_em_wh_stats.is_rep_rep b
                 ON ( a.is_rep_id = b.is_rep_parent_id )
               join (SELECT is_rep_id,
                            em_user_abbrev
                     FROM   mstr_em_wh_stats.is_rep_fact
                            join mstr_em_wh_stats.em_user
                              ON ( is_rep_fact.em_user_id = em_user.em_user_id )
                     WHERE  day_id between'20130828'and'20131028'
                            AND (Lower(em_user_abbrev) LIKE'%mstr%'OR
                                 Lower(em_user_abbrev) = 'administrator')
                     GROUP  BY is_rep_id,
                               em_user_abbrev) c
                 ON ( c.is_rep_id = b.is_rep_child_id )
        WHERE  a.day_id between'20130828'and'20131028'
        GROUP  BY c.em_user_abbrev,
                  a.em_user_id,
                  c.is_rep_id) mt1
       join mstr_em_wh_stats.is_rep rp2
         ON ( mt1.is_rep_id = rp2.is_rep_id )
       join mstr_em_wh_stats.em_user ur3
         ON ( mt1.em_user_id = ur3.em_user_id )
GROUP  BY mt1.em_user_abbrev,
          rp2.is_rep_name,
          ur3.em_user_abbrev
0
Comment
Question by:anshuma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39825713
Sorry for the previous post... I can reproduce the error.
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 total points
ID: 39825714
Change: UNIONALL
to: UNION ALL
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 39826004
Put your query in an editor like TOAD, SQL Developer, Notepad++ - they will show you missing parentheses :)
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 1000 total points
ID: 39826509
The unionall (on line 27) without a space certainly jumped out as a problem as slightwv pointed out. However, I tried to replicate the error and got a different error message. Are you still getting an error after changing the unionall to union all?
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39827025
When I changed to 'union all' I get the 942 table or view does not exist.  That told me the syntax was correct.

I didn't take the time to create the columns and tables involved.

What error did you get?

>> they will show you missing parentheses :)

It isn't a missing parenthesis. Did you load it up into one of your suggested tools to locate it?
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question