Solved

please fix an oracle query

Posted on 2014-01-31
5
307 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
  • 3
5 Comments
 
LVL 76

Expert Comment

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

Accepted Solution

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

Expert Comment

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

Assisted Solution

by:awking00
awking00 earned 250 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 76

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now