Why this query is giving error in report

I have a simple query ...
SELECT &P_FLEXDATA C_FLEXDATA,
CHART_OF_ACCOUNTS_ID C_NUM
FROM GL_CODE_COMBINATIONS
It is running fine in SQL prompt but when I create it as a report query then it is giving error: ORA-00904 "C_FLEXDATA": invalid identifier
Please advise ....
I shall be ever thankful...
Best Regards

Hello,
You are using a "lexical" reference in the SQL query (&P_FLEXDATA).
You must set a default value for P_FLEXDATA in order the SQL Query to be parsed successfuly
Regards

Similar Messages

  • Why this Query is taking much longer time than expected?

    Hi,
    I need experts support on the below mentioned issue:
    Why this Query is taking much longer time than expected? Sometimes I am getting connection timeout error. Is there any better way to achieve result in shortest time.  Below, please find the DDL & DML:
    DDL
    BHDCollections
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[BHDCollections](
     [BHDCollectionid] [bigint] IDENTITY(1,1) NOT NULL,
     [GroupMemberid] [int] NOT NULL,
     [BHDDate] [datetime] NOT NULL,
     [BHDShift] [varchar](10) NULL,
     [SlipValue] [decimal](18, 3) NOT NULL,
     [ProcessedValue] [decimal](18, 3) NOT NULL,
     [BHDRemarks] [varchar](500) NULL,
     [Createdby] [varchar](50) NULL,
     [Createdon] [datetime] NULL,
     CONSTRAINT [PK_BHDCollections] PRIMARY KEY CLUSTERED
     [BHDCollectionid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    BHDCollectionsDet
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[BHDCollectionsDet](
     [CollectionDetailid] [bigint] IDENTITY(1,1) NOT NULL,
     [BHDCollectionid] [bigint] NOT NULL,
     [Currencyid] [int] NOT NULL,
     [Denomination] [decimal](18, 3) NOT NULL,
     [Quantity] [int] NOT NULL,
     CONSTRAINT [PK_BHDCollectionsDet] PRIMARY KEY CLUSTERED
     [CollectionDetailid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    Banks
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Banks](
     [Bankid] [int] IDENTITY(1,1) NOT NULL,
     [Bankname] [varchar](50) NOT NULL,
     [Bankabbr] [varchar](50) NULL,
     [BankContact] [varchar](50) NULL,
     [BankTel] [varchar](25) NULL,
     [BankFax] [varchar](25) NULL,
     [BankEmail] [varchar](50) NULL,
     [BankActive] [bit] NULL,
     [Createdby] [varchar](50) NULL,
     [Createdon] [datetime] NULL,
     CONSTRAINT [PK_Banks] PRIMARY KEY CLUSTERED
     [Bankid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    Groupmembers
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[GroupMembers](
     [GroupMemberid] [int] IDENTITY(1,1) NOT NULL,
     [Groupid] [int] NOT NULL,
     [BAID] [int] NOT NULL,
     [Createdby] [varchar](50) NULL,
     [Createdon] [datetime] NULL,
     CONSTRAINT [PK_GroupMembers] PRIMARY KEY CLUSTERED
     [GroupMemberid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    ALTER TABLE [dbo].[GroupMembers]  WITH CHECK ADD  CONSTRAINT [FK_GroupMembers_BankAccounts] FOREIGN KEY([BAID])
    REFERENCES [dbo].[BankAccounts] ([BAID])
    GO
    ALTER TABLE [dbo].[GroupMembers] CHECK CONSTRAINT [FK_GroupMembers_BankAccounts]
    GO
    ALTER TABLE [dbo].[GroupMembers]  WITH CHECK ADD  CONSTRAINT [FK_GroupMembers_Groups] FOREIGN KEY([Groupid])
    REFERENCES [dbo].[Groups] ([Groupid])
    GO
    ALTER TABLE [dbo].[GroupMembers] CHECK CONSTRAINT [FK_GroupMembers_Groups]
    BankAccounts
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[BankAccounts](
     [BAID] [int] IDENTITY(1,1) NOT NULL,
     [CustomerID] [int] NOT NULL,
     [Locationid] [varchar](25) NOT NULL,
     [Bankid] [int] NOT NULL,
     [BankAccountNo] [varchar](50) NOT NULL,
     CONSTRAINT [PK_BankAccounts] PRIMARY KEY CLUSTERED
     [BAID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    ALTER TABLE [dbo].[BankAccounts]  WITH CHECK ADD  CONSTRAINT [FK_BankAccounts_Banks] FOREIGN KEY([Bankid])
    REFERENCES [dbo].[Banks] ([Bankid])
    GO
    ALTER TABLE [dbo].[BankAccounts] CHECK CONSTRAINT [FK_BankAccounts_Banks]
    GO
    ALTER TABLE [dbo].[BankAccounts]  WITH CHECK ADD  CONSTRAINT [FK_BankAccounts_Locations1] FOREIGN KEY([Locationid])
    REFERENCES [dbo].[Locations] ([Locationid])
    GO
    ALTER TABLE [dbo].[BankAccounts] CHECK CONSTRAINT [FK_BankAccounts_Locations1]
    Currency
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Currency](
     [Currencyid] [int] IDENTITY(1,1) NOT NULL,
     [CurrencyISOCode] [varchar](20) NOT NULL,
     [CurrencyCountry] [varchar](50) NULL,
     [Currency] [varchar](50) NULL,
     CONSTRAINT [PK_Currency] PRIMARY KEY CLUSTERED
     [Currencyid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    CurrencyDetails
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[CurrencyDetails](
     [CurDenid] [int] IDENTITY(1,1) NOT NULL,
     [Currencyid] [int] NOT NULL,
     [Denomination] [decimal](15, 3) NOT NULL,
     [DenominationType] [varchar](25) NOT NULL,
     CONSTRAINT [PK_CurrencyDetails] PRIMARY KEY CLUSTERED
     [CurDenid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    QUERY
    WITH TEMP_TABLE AS
    SELECT     0 AS COINS, BHDCollectionsDet.Quantity AS BN, BHDCollections.BHDDate AS CollectionDate, BHDCollectionsDet.Currencyid,
                          (BHDCollections.BHDCollectionid) AS DSLIPS, Banks.Bankname
    FROM         BHDCollections INNER JOIN
                          BHDCollectionsDet ON BHDCollections.BHDCollectionid = BHDCollectionsDet.BHDCollectionid INNER JOIN
                          GroupMembers ON BHDCollections.GroupMemberid = GroupMembers.GroupMemberid INNER JOIN
                          BankAccounts ON GroupMembers.BAID = BankAccounts.BAID INNER JOIN
                          Currency ON BHDCollectionsDet.Currencyid = Currency.Currencyid INNER JOIN
                          CurrencyDetails ON Currency.Currencyid = CurrencyDetails.Currencyid INNER JOIN
                          Banks ON BankAccounts.Bankid = Banks.Bankid
    GROUP BY BHDCollectionsDet.Quantity, BHDCollections.BHDDate, BankAccounts.Bankid, BHDCollectionsDet.Currencyid, CurrencyDetails.DenominationType,
                          CurrencyDetails.Denomination, BHDCollectionsDet.Denomination, Banks.Bankname,BHDCollections.BHDCollectionid
    HAVING      (BHDCollections.BHDDate BETWEEN @FromDate AND @ToDate) AND (BankAccounts.Bankid = @Bankid) AND (CurrencyDetails.DenominationType = 'Currency') AND
                          (CurrencyDetails.Denomination = BHDCollectionsDet.Denomination)
    UNION ALL
    SELECT     BHDCollectionsDet.Quantity AS COINS, 0 AS BN, BHDCollections.BHDDate AS CollectionDate, BHDCollectionsDet.Currencyid,
                          (BHDCollections.BHDCollectionid) AS DSLIPS, Banks.Bankname
    FROM         BHDCollections INNER JOIN
                          BHDCollectionsDet ON BHDCollections.BHDCollectionid = BHDCollectionsDet.BHDCollectionid INNER JOIN
                          GroupMembers ON BHDCollections.GroupMemberid = GroupMembers.GroupMemberid INNER JOIN
                          BankAccounts ON GroupMembers.BAID = BankAccounts.BAID INNER JOIN
                          Currency ON BHDCollectionsDet.Currencyid = Currency.Currencyid INNER JOIN
                          CurrencyDetails ON Currency.Currencyid = CurrencyDetails.Currencyid INNER JOIN
                          Banks ON BankAccounts.Bankid = Banks.Bankid
    GROUP BY BHDCollectionsDet.Quantity, BHDCollections.BHDDate, BankAccounts.Bankid, BHDCollectionsDet.Currencyid, CurrencyDetails.DenominationType,
                          CurrencyDetails.Denomination, BHDCollectionsDet.Denomination, Banks.Bankname,BHDCollections.BHDCollectionid
    HAVING      (BHDCollections.BHDDate BETWEEN @FromDate AND @ToDate) AND (BankAccounts.Bankid = @Bankid) AND (CurrencyDetails.DenominationType = 'COIN') AND
                          (CurrencyDetails.Denomination = BHDCollectionsDet.Denomination)),
    TEMP_TABLE2 AS
    SELECT CollectionDate,Bankname,DSLIPS AS DSLIPS,SUM(BN) AS BN,SUM(COINS)AS COINS  FROM TEMP_TABLE Group By CollectionDate,DSLIPS,Bankname
    SELECT CollectionDate,Bankname,count(DSLIPS) AS DSLIPS,sum(BN) AS BN,sum(COINS) AS coins FROM TEMP_TABLE2 Group By CollectionDate,Bankname
    HAVING COUNT(DSLIPS)<>0;

    Without seeing an execution plan of the query it is hard to suggest something useful. Try insert the result of UNION ALL to the temporary table and then perform an aggregation on that table, not a CTE.
    Just
    SELECT CollectionDate,Bankname,DSLIPS AS DSLIPS,SUM(BN) AS BN,SUM(COINS)AS COINS  FROM
    #tmp Group By CollectionDate,DSLIPS,Bankname
    HAVING COUNT(DSLIPS)<>0;
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Why this query required 2 extra columns in GROUP BY

    Hi All,
    This is my query:
    SELECT "parent_level_id",
           "parent_level_name"
           "parent_level_id",                    
           "child_level_id",
           "child_level_name",
           "scenario_id",
           "scenario_name",
           "exported",
           "regress_cob",
           "scn_status_id",
           "tgt_scenario_name",
           "load_status_id",
           "load_count",
           "PRESENT_VALUE",
           "DELTA",
           "GAMMA",
           "VEGA",
           "PNL",
           "ORIGINAL_PRESENT_VALUE"
    FROM
    select   0-fssPV.feed_id                        as "parent_level_id",
             fssPV.feed_description                 as "parent_level_name",
             fssPV.book_id                          as "child_level_id",
             fssPV.book_display_name                as "child_level_name",
             fssPV.parent_scenario_id               as "scenario_id",
             fssPV.scenario_display_name            as "scenario_name",
             nvl(sc.exported, 'N')                  as "exported",
             nvl(fssPV.parent_regressed_cob_date,  fssPV.parent_cob_date)    as "regress_cob",
             fssPV.scn_status_id                    as "scn_status_id",
             fssPV.tgt_scenario_display_name        as "tgt_scenario_name",
             fssPV.load_status_id                   as "load_status_id",
             count(*)                               as "load_count",
            sum(fssPV.present_value)                as "PRESENT_VALUE",
             sum(fssPV.delta)                       as "DELTA",
             sum(fssPV.gamma)                       as "GAMMA",
             sum(fssPV.vega)                        as "VEGA",
             sum(fssPV.present_value) - sum (srbase.present_value) as "PNL",
                select SUM(vsr.original_present_value)
                from validated_position vp , validated_scenario_result vsr
                where
                VSR.FEED_INSTANCE_ID= fssPV.feed_instance_id
                AND VSR.COB_DATE= fssPV.cob_date
                and vsr.validated_position_id= vp.validated_position_id
                 AND vsr.scenario_id in  (SELECT   distinct mn.node_id as "SCENARIO_ID"
                                           FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
                                                    marsnode mn
                                           WHERE    nodeIds.column_value = mn.node_id
                                           AND      mn.close_date is null
             ) "ORIGINAL_PRESENT_VALUE"
    from   (
    select fssTgts.*,
           mntgt.display_name        as "TGT_SCENARIO_DISPLAY_NAME",
           mnscenario.display_name   as "SCENARIO_DISPLAY_NAME",
           mnbook.display_name       as "BOOK_DISPLAY_NAME",
           fs.feed_description,
           sr.present_value,
           sr.delta,
           sr.gamma,
           sr.vega,
           p.position_id
    from (
    /** Treewalk to find Feed/Scenario dependencies **/
    Select fssBooks.feed_id,
           fssLinks.cob_date,
           fssLinks.scenario_id,
           fssBooks.load_status_id,
           fssBooks.scn_status_id,
           fssBooks.tgt_scenario_id,
           fssBooks.book_id,
           fssBooks.regressed_cob_date,
           fssLinks.feed_instance_id,
           fssLinks.parent_cob_date,
           fssLinks.parent_tgt_scenario_id,
           fssLinks.parent_regressed_cob_date,
           fssLinks.parent_scenario_id,
           fssLinks.parent_feed_instance_id
    from   (
    /** Treewalk (backwards) to find underlying data over FSS control table **/
    WITH fss AS
             /* Initial filter on feed_scenario_status for peformance           */
             /* cannot filter on scenario as we don't know the dependencies yet */
             ( select DISTINCT scenario_id,
                      f.cob_date,
                      f.scn_status_id,
                      f.regressed_cob_date,
                      f.tgt_scenario_id,
                      f.feed_id,
                      f.feed_instance_id
               from   feed_scenario_status f,
                      feed_group_xref fgx
               where    cob_date <= l_cobdate -- PVs for this cob must be loaded either today, or its regressed to a previous cob
               and    f.feed_id = fgx.feed_id
               and    fgx.feed_group_id like l_feed_group_id
               and    fgx.feed_id like l_feed_id
      select   feed_instance_id,
               scenario_id,
               prior scenario_id,
               cob_date,
               feed_id,
               scn_status_id,
               regressed_cob_date,
               /* Need to maintain the root values to identify the scenarios that users are seeing */
               CONNECT_BY_ISLEAF "ISLEAF",
               CONNECT_BY_ROOT scenario_id        as "PARENT_SCENARIO_ID",
               CONNECT_BY_ROOT feed_id            as "PARENT_FEED_ID",
               CONNECT_BY_ROOT cob_date           as "PARENT_COB_DATE",
               CONNECT_BY_ROOT tgt_scenario_id    as "PARENT_TGT_SCENARIO_ID",
               CONNECT_BY_ROOT regressed_cob_date as "PARENT_REGRESSED_COB_DATE",
               CONNECT_BY_ROOT feed_instance_id   as "PARENT_FEED_INSTANCE_ID"
      from     fss
      start with fss.cob_date = l_cobdate
      connect by (prior fss.regressed_cob_date = fss.cob_date and
                  prior fss.scenario_id = fss.scenario_id and
                  prior fss.feed_id = fss.feed_id and
                  prior fss.tgt_scenario_id is null
                 ) -- Connect if regressed (rule: same feed/book/scenario, different cob)
              or (prior fss.tgt_scenario_id = fss.scenario_id and
                  prior fss.cob_date = fss.cob_date and
                  prior fss.feed_id = fss.feed_id and
                  prior fss.feed_instance_id = fss.feed_instance_id
                 ) -- and connect if paste as (rule: same feed/cob/book, different scenario)
      ) fssLinks,
      feed_scenario_status fssBooks
    where isLeaf = 1
    and   fssLinks.parent_feed_id = fssBooks.feed_Id
    and   fssLinks.parent_cob_date = fssBooks.cob_date
    and   fssLinks.parent_scenario_id = fssBooks.scenario_id
    ) fssTgts,
    position p,
    scenario_result sr,
    marsnode mntgt,
    marsnode mnbook,
    marsnode mnscenario,
    feed_static fs
    where fssTgts.feed_id = fs.feed_id
    and   fssTgts.parent_tgt_scenario_id = mntgt.node_id (+)
    and   mntgt.close_date (+) is null
    and   fssTgts.feed_instance_id = p.feed_instance_id
    and   fssTgts.book_id = p.book_id
    and   fssTgts.cob_date = sr.cob_date
    and   fssTgts.scenario_id = sr.scenario_id
    and   p.feed_instance_id = sr.feed_instance_id
    and   p.position_id = sr.position_id
    and   p.book_id = mnbook.node_id
    and   mnbook.close_date is null
    and   fssTgts.parent_scenario_id = mnscenario.node_id
    and   mnscenario.close_date is null
    ) fssPV
    left outer join scenario_control sc
      on fssPV.parent_feed_instance_id = sc.feed_instance_id
      and upper(fssPV.scenario_display_name) = upper(sc.scenario)
    /* Join to SBM to calculate P&Ls */
    left outer join scenario_base_map sbm
      on  fssPV.scenario_id = sbm.scenario_id
      and sbm.begin_cob_date <= l_cobdate
      and sbm.end_cob_date > l_cobdate
    left outer join scenario_result srbase
      on  fssPV.cob_date = srbase.cob_date
      and fssPV.feed_instance_id = srbase.feed_instance_id
      and nvl(sbm.mapped_scenario_id, l_original_scn_id) = srbase.scenario_id
      and fssPV.position_id = srbase.position_id
    /* Only display (root) scenarios that users have selected */
    where fssPV.parent_scenario_id in (SELECT   distinct mn.node_id as "SCENARIO_ID"
                                       FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
                                                marsnode mn
                                       WHERE    nodeIds.column_value = mn.node_id
                                       AND      mn.close_date is null
    group by fssPV.feed_id,
             fssPV.feed_description,
             fssPV.book_id,
             fssPV.book_display_name,
             fssPV.parent_scenario_id,
             fssPV.scenario_display_name,
             sc.exported,
             fssPV.parent_regressed_cob_date,
             fssPV.scn_status_id,
             fssPV.tgt_scenario_display_name,
             fssPV.load_status_id,
             fssPV.parent_cob_date
    --         fssPV.feed_instance_id,
    --         fssPV.cob_date
    );In this query for the initial section where I am selecting the "ORIGINAL_PRESENT_VALUE" part
                select SUM(vsr.original_present_value)
                from validated_position vp , validated_scenario_result vsr
                where
                VSR.FEED_INSTANCE_ID= fssPV.feed_instance_id
                AND VSR.COB_DATE= fssPV.cob_date
                and vsr.validated_position_id= vp.validated_position_id
                 AND vsr.scenario_id in  (SELECT   distinct mn.node_id as "SCENARIO_ID"
                                           FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
                                                    marsnode mn
                                           WHERE    nodeIds.column_value = mn.node_id
                                           AND      mn.close_date is null
             ) "ORIGINAL_PRESENT_VALUE" Even though fssPV.feed_instance_id and fssPV.cob_date are not used anywhere in the SELECT clause requires tobe added to the final GROUP BY clause else
    the query though compiles successfully doesnt executes giving "Not a group by " error.
    Can anyone tell me why this is the problem and why these columns need to be added to the final GROUP BY clause.
    Rgds,
    Aashish

    Hi, Aashish,
    Aashish S. wrote:
    Even though fssPV.feed_instance_id and fssPV.cob_date are not used anywhere in the SELECT clause requires tobe added to the final GROUP BY clause else
    the query though compiles successfully doesnt executes giving "Not a group by " error.Actually, you are using both of those columns in the SELECT clause, when you compute original_present_value:
    select SUM(vsr.original_present_value)
    from validated_position vp , validated_scenario_result vsr
    where
    VSR.FEED_INSTANCE_ID= fssPV.feed_instance_id
    AND VSR.COB_DATE= fssPV.cob_date
    and vsr.validated_position_id= vp.validated_position_id
    AND vsr.scenario_id in  (SELECT   distinct mn.node_id as "SCENARIO_ID"
    FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
    marsnode mn
    WHERE    nodeIds.column_value = mn.node_id
    AND      mn.close_date is null
    ) "ORIGINAL_PRESENT_VALUE" Since the scalar sub-query is correlated to fsspv.feed_instance_id and fsspv.cob_date, it is depenedant on those columns, the same as, say TRUNC (fsspv.cobb_date, 'YEAR') is depenedant on fsspv.cob_date.
    Perhaps you need to put SUM in the main query, not the scalar sub-query, or (probably faster) replace the scalar sub-query with a join. Without knowing your tables, or the results you want from your data, I can't say more.
    Whenever you have a problem, post a little sample data (CREATED TABLE and INSERT statements for all tables), and the results you want from that data.
    Simplify the problem as much as possible. In this case, I think you can show what the problem is using just two tables, the ones aliases fsspv and mn.
    If you can illustrate your problem using commonly available tables, like those in the scott schema, then you don't have to post any data; just the results you want.
    It looks like you're doing something like this:
    SELECT       job
    ,       COUNT (*)     AS cnt
    ,       (          -- Begin scalar sub_query to compute min_loc
                SELECT     MIN (loc)
              FROM     scott.dept
              WHERE     deptno     = e.deptno
           ) min_loc     -- End scalar sub_query to compute min_loc
    FROM       scott.emp     e
    GROUP BY  job
    ,            deptno     -- Omitting this causes ORA_00979: not a GROUP BY expression
    ;when you really should be doing something like this:
    SELECT       job
    ,       COUNT (*)     AS cnt
    ,       MIN ( (          -- Begin scalar sub_query to compute min_loc
                SELECT     loc
              FROM     scott.dept
              WHERE     deptno     = e.deptno
               ) ) min_loc     -- End scalar sub_query to compute min_loc
    FROM       scott.emp     e
    GROUP BY  job
    ;to get these results:
    JOB              CNT MIN_LOC
    CLERK              4 CHICAGO
    SALESMAN           4 CHICAGO
    PRESIDENT          1 NEW YORK
    MANAGER            3 CHICAGO
    ANALYST            2 DALLAS

  • Why this query does not show the result?

    Why the query with the schema prefixed does not show the result and the query without schema display the correct results?
    SQL> select data_object_id,object_type from dba_objects where object_name='HR'.'JOBS';
    select data_object_id,object_type from dba_objects where object_name='HR'.'JOBS'
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> select data_object_id,object_type from dba_objects where object_name='HR.JOBS';
    no rows selected
    SQL> select data_object_id, OWNER, object_type from dba_objects where object_name='JOBS';
    DATA_OBJECT_ID     OWNER                          OBJECT_TYPE
    69662              HR                                 TABLE
                       OE                                 SYNONYM
    SQL> SELECT USER FROM DUAL;
    USER
    SYS

    Hi,
    the column object_name refers to a object_name which is 'JOBS', the column owner refers to the owner 'HR', the value isn't stored together, so you have to select the two columns. It is the same behaviour as every other table/view. Have a look at the values in the view DBA_OBJECTS.
    Herald ten Dam
    Superconsult.nl

  • Why would this query return an error that mentions an entirely different database being offline?

    Trying to get a list of fragmented indexes based on a database name.  However, 
    SELECT COUNT(*) AS TableFragOver80PctCount
    FROM sys.dm_db_index_physical_stats (null, null, null, null, null )as ts
    INNER JOIN sys.tables t on t.[object_id] = ts.[object_id]
    INNER JOIN sys.indexes i on i.[object_id] = ts.[object_id]
    INNER JOIN sys.databases db ON ts.database_id = db.database_id
    WHERE db.name = 'MY DB NAME'
    AND ts.avg_fragmentation_in_percent > 80.00
    The error I get back 
    Msg 942, Level 14, State 4, Line 1
    Database 'VERY DIFFERENT DB' cannot be opened because it is offline.
    I know there is a database on this server that is offline, actually 2 or 3, but not the one Im trying to get information about.  What could cause the above query to have trouble getting index info that is caused by an entirely different database being
    offline?

    FROM sys.dm_db_index_physical_stats (null, null, null, null, null )as ts
    See MSDN sys.dm_db_index_physical_stats
    ;  the first parameter is the database id; if you pass NULL as here, then all databases will be scanned, also your offline one.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • This Query IS giving divide by zero error when executed in sql plus

    UPDATE grn G
    SET g.OPT_WA_FAIR_VAL_A = (SELECT
    ROUND(SUM(NVL(ga.OPT_FAIR_VAL_A, 0) * NVL(gvs.GRN_VEST_OPT_Q, 0)) / SUM(NVL(gvs.GRN_VEST_OPT_Q, 0)), 6)
    FROM
    GRANT_VESTING_SCHEDULE gvs,
    GRANT_ASSUMPTION ga
    WHERE
    gvs.ORG_GRP_I = ga.ORG_GRP_I AND
    gvs.grn_n = ga.grn_n AND
    ga.ORG_GRP_I = g.ORG_GRP_I AND
    ga.GRN_N = g.GRN_N AND
    NVL(ga.GRN_ASMPN_EFF_D, gvs.grn_vest_d) <= gvs.grn_vest_d AND
    NVL(ga.GRN_ASMPN_END_D, gvs.grn_vest_d) >= gvs.grn_vest_d
    WHERE G.ORG_GRP_I =5
    Any suggestions

    hi
    What should be result if divide by zero e.g
    SQL> SELECT * FROM emp;
        EMPNO ENAME        JOB             MGR HIREDATE        SAL      COMM    DEPTNO
         7901 SMITH        CLERK          7902 17-DEC-80         0         0        20
         7499 ALLEN        SALESMAN       7698 20-FEB-81      2100      1800        30
         7521 WARD         SALESMAN       7698 22-FEB-81      2300      2000        30
         7566 JONES        MANAGER        7839 02-APR-81      1000      3000        20
         7654 MARTIN       SALESMAN       7698 28-SEP-81      3200       700        30
         7698 BLAKE        MANAGER        7839 01-MAY-81      1000      3000        30
         7782 CLARK        MANAGER        7839 09-JUN-81      1000      3000        10
         7788 SCOTT        ANALYST        7566 19-APR-87      1000      1900        20
         7839 KING         PRESIDENT           17-NOV-81      1000      1700        10
         7844 TURNER       SALESMAN       7698 08-SEP-81      1800       700        30
         7876 ADAMS        CLERK          7788 23-MAY-87      1000      1300        20
         7900 JAMES        MANAGER        7698 03-DEC-81      1000      3000        30
         7902 FORD         ANALYST        7566 03-DEC-81      1000      2000        20
    13 rows selected.
    SQL> SELECT sal/DECODE(comm,0,1,comm) FROM emp;
    SAL/DECODE(COMM,0,1,COMM)
                            0
                    1.1666667
                         1.15
                    .33333333
                    4.5714286
                    .33333333
                    .33333333
                    .52631579
                    .58823529
                    2.5714286
                    .76923077
                    .33333333
                           .5
    13 rows selected.Khurram

  • Silly old fogey (me) cannot figure out why this query returns 1 row

    Hi all,
    In reference to {thread:id=2456973}, why does
    select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
    , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
    from emp group by job;only return 1 row and not 1 for each job? I actually had to test it myself to believe it.
    It returns data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)Using only a single aggregate (either count or sum) returns 1 row per job, as expected

    John Stegeman wrote:
    It returns data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
    from emp group by job)
    Exactly the point ;-)
    Seems like Oracle actually can do a "double group by" in the same operation.
    Witness the explain plans in this example:
    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3  from scott.emp group by job;
        CLERKS  SALESMANS
             0          0
             0          0
             0          0
             0          4
             4          0
    Execution Plan
    Plan hash value: 1697595674
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  HASH GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------And compare it to this one with the double aggregates:
    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3  from scott.emp group by job;
        CLERKS  SALESMANS
             4          4
    Execution Plan
    Plan hash value: 417468012
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------There is both HASH GROUP BY and SORT AGGREGATE.
    It does not really make sense to do an aggregate on an aggregate - if both aggregates are used "on the same group-by level".
    The sum() aggregates are used upon an already aggregated value, so it does look like Oracle actually treats that as "first do the inner aggregate using the specified group by and then do the outer aggregate on the result with no group by."
    Look at this example where I combine "double" aggregates with "single" aggregates:
    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2
      4       , count(*) COUNTS
      5  from scott.emp group by job;
        CLERKS  SALESMANS SALESMANS2     COUNTS
             4          4          1          5
    Execution Plan
    Plan hash value: 417468012
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------When mixing "double" and "single" aggregates, Oracle decides that single aggregates belong in the "outer" aggregation.
    SALESMAN2 is doing a count on the aggregated job column that is the result of the "inner" group by - therefore only 1.
    The count(*) also counts the result of the "inner" aggregation.
    I am not sure if this is documented or if it is a "sideeffect" of either the internal code used for GROUPING SETS or the internal code used for allowing analytic functions like this:
    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3       , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2
      4       , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2
      5  from scott.emp group by job;
        CLERKS  SALESMANS    CLERKS2 SALESMANS2
             0          0          4          4
             4          0          4          4
             0          0          4          4
             0          0          4          4
             0          4          4          4
    Execution Plan
    Plan hash value: 4115955660
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  WINDOW BUFFER      |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   SORT GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------Personally I think I would have preferred if Oracle raised an error on this "double aggregation" and thus require me to write it this way (if that is the result I desired):
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)I can not really think of good use-cases for the "double aggregation" - but rather that it could give you unnoticed bugs in your code if you happen to do double aggregation without noticing it.
    Interesting thing to know ;-)

  • Exe giving error for report generation and LV 8.6.1

    I have created and installed a labview application in a PC(windows XP) where labview is not installed.  (already included NI_Excel.lvclass)
    I have used a report(excel) generation to display the results.
    I am getting following error:
    Error Code: -2147352573
    Member not found in NI_Excel.lvclass:
    I am using MS office Excel 2007 SP1
    NI LabVIEW Run-Time Engine:8.6.1.
    Report generation toolkit version:1.1.3
    phani srikanth
    Solved!
    Go to Solution.
    Attachments:
    Error.JPG ‏10 KB

    search the ni website and a 30 day eval copy can be found. For use beyond this period you would have to buy a license (unless you have one of course)
    compatibility can be found on the following link
    http://digital.ni.com/public.nsf/allkb/C9408B9F08D711E786256F3300701D01 
    hope it helps
    TD 
    Please remember to accept any solutions and give kudos, Thanks
    LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7

  • I cannot open my FinalCut pro X because of a problem with the FxFactory plugin, at least this is what the error message reports me. What should I do? Thank you very much

     

    What does the error message say exactly?
    Please contact tech support through the FxFactory application and explain your problem in as much detail as possible. 
    This will attach a FxFactory generated System profile to your message which can be very helpful in diagnosing problems on your system:
    1) Launch the FxFactory application
    2) Choose the "Contact Tech Support..." command under the Help menu.

  • Why is FrameMaker 12 giving error message "FrameMaker has encountered a serious error?"

    Hi All,
    I have a couple people that are experiencing the exact same thing.  They are all using FrameMaker 12 Structured mode, and when they are trying to open up certain files, this is what they experience.
    I have un-installed and re-installed the software and still no luck.  I have already sent an email to [email protected], but I was just going to post on the forum to see if anyone else has ever had this happen to them.  They can also open up some files, but the one's that they are needing to open up aren't working.  Any help is appreciated.

    That pretty much points the finger at the file(s) as being somehow corrupt. If you can just open the file and it doesn't crash before working on it, then you should immediately try saving as MIF. If this works, then opening the MIF and re-saving as the binary .fm might just clean out the corruption.
    As a last resort, you could try using FM's Heroic Open.
    1. Open/create a blank FM document (File > New > Document).
    2. Use the <esc> o H  shortcut ( it's the lowercase "O") - press the keys in sequence, not simultaneously.
    3. Select the bad file from the browser and keep your fingers crossed.

  • Intermittent  Error Running Report

    I have an intermittent issue with the WPF report Viewer.  I run a report and get the window open with the busy circle as per normal but then there is a  Invalid report file path error appearin, then a blank report is shown in the viewer.   If I run the report again everything is fine.   Can anyone help to explain why this is happening
    The error being reported is.
    Error Exception: SEHException
    Error Message: External component has thrown an exception.
    Error Stack Trace:
       at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.RemoveAfterFormatPageEventCallBack(ISCRAfterFormatPageEventCallBack formatPageEventCallBack)  
    at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.RemoveAfterFormatPageEventCallBack(ISCRAfterFormatPageEventCallBack eventCallback)   
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.ClearCache(Boolean clearDocument)   
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.InternalClose(Boolean bSetupForNextReport)   
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.Close()
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)  
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport()
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_Database()
    at ....ReportViewer.CleanUpObjectsForMemoryLeak() in ...ReportViewer.xaml.cs:line 307     at ....ReportViewer.Window_Unloaded(Object sender, RoutedEventArgs e) in..\ReportViewer.xaml.cs:line 297  
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)   
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)  
    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)   
    at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)   
    at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)   
    at System.Windows.BroadcastEventHelper.BroadcastUnloadedEvent(Object root)   
    at MS.Internal.LoadedOrUnloadedOperation.DoWork()  
    at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
    at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
    at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)  
    at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)  
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)   
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)  
    FYI the CleanUpObjectsForMemoryLeak code is listed below and all references - which should only be on window close or disposal of window
            private void CleanUpObjectsForMemoryLeak()
                if (this.vwCrystalReportViewer != null)
                    var objRptDocViewer = (ReportDocument)this.vwCrystalReportViewer.ViewerCore.ReportSource;
                    if (objRptDocViewer != null)
                        foreach (CrystalDecisions.CrystalReports.Engine.Table table in objRptDocViewer.Database.Tables)
                            table.Dispose();
                        }// Line 297
                        objRptDocViewer.Database.Dispose();
                        objRptDocViewer.Close();
                        objRptDocViewer.Dispose();
                        objRptDoc.Close();
                        objRptDoc.Dispose();
                        objRptDoc = null;
                    this.ParameterValues = null;
                    this.PassedReport = null; //Line 307
                    if (this.vwCrystalReportViewer.ViewerCore.ParameterFieldInfo != null)
                        this.vwCrystalReportViewer.ViewerCore.ParameterFieldInfo.Clear();
                    if (this.vwCrystalReportViewer.ViewerCore != null)
                        this.vwCrystalReportViewer.ViewerCore.Content = null;
                        this.vwCrystalReportViewer.ViewerCore.Dispose();
                    if (this.vwCrystalReportViewer.Owner != null)
                        this.vwCrystalReportViewer.Owner = null;
                    this.vwCrystalReportViewer = null;
                    GC.Collect();
    private void Window_Unloaded(object sender, RoutedEventArgs e)
                CleanUpObjectsForMemoryLeak();
            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
               e.Cancel = true;
                CleanUpObjectsForMemoryLeak();
                this.Visibility = System.Windows.Visibility.Collapsed;
    ~ReportViewer()
                try
                    CleanUpObjectsForMemoryLeak();
                finally { }

    Couple of things I'd do differently.
    1) Load the report object using the engine, not the viewer:
    objRptDoc.Load = <path to the report>
    2) You really do not need all that viewer clean up code (but that would just be my preference):
    if (this.vwCrystalReportViewer.ViewerCore != null)
                        this.vwCrystalReportViewer.ViewerCore.Content = null;
                        this.vwCrystalReportViewer.ViewerCore.Dispose();
                    if (this.vwCrystalReportViewer.Owner != null)
                        this.vwCrystalReportViewer.Owner = null;
                    this.vwCrystalReportViewer = null;
                    GC.Collect();
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • I found a bug in Power Query. Anyone know why this occurs?

    It took some time to isolate the cause of this.
    One of our SharePoint sites couldn't successfully be connected to with Power Query for Excel 2013.  We would receive this message: "DataSource.Error: OData: The feed's metadata document appears to be invalid."
    I made a site template and started making copies of the failing site in order to test the cause of the error.
    I narrowed it down to 16 lists that, if present on the site, would cause the connection to fail.  Those lists' names were simply numbers.  For example: "1", "2", etc.
    I noticed in the Listdata.svc feed for the site that only the choice columns were included in the metadata and not the single line of text column names.  In Listdata.svc, it appends a "c_" in front of the both the list and choice column
    names if the list name starts with a number.
    After many tests I believe I have confirmed you cannot start the name of a list with a number IF you have a choice column in that list.  Anyone know why this is?

    Hi,
    Thanks for reporting this issue. Would you be able to capture some Fiddler traces and send them our way so we can take a closer look at the underlying errors?
    Feel free to send them via "Send a Frown" in PQ for privacy.
    Thanks,
    M.

  • Why don't this query fails??

    Hi All,
    A little brainstorming ....
    I am providing the sql here..
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Connected as dss
    SQL>
    SQL>   UPDATE dw_mmg_cat_us
      2    SET    dw_eftv_to = TRUNC(sysdate)
      3    WHERE  (mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id) IN
      4           (SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
      5           FROM   dw_mmg_cat_us
      6           WHERE  dw_eftv_to is null
      7           AND    mcv_mc_mc_id = 'DUMP_NO'
      8           MINUS
      9           SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
    10           FROM   merc_mmg_catus
    11          WHERE  mcv_mc_mc_id = 'DUMP_NO');
    0 rows updated
    SQL>
    SQL> SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
      2  FROM   dw_mmg_cat_us
      3  WHERE  dw_eftv_to is null
      4  AND    mcv_mc_mc_id = 'DUMP_NO'
      5  MINUS
      6  SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
      7  FROM   merc_mmg_catus
      8  WHERE  mcv_mc_mc_id = 'DUMP_NO'
      9  /
    SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
    FROM   dw_mmg_cat_us
    WHERE  dw_eftv_to is null
    AND    mcv_mc_mc_id = 'DUMP_NO'
    MINUS
    SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
    FROM   merc_mmg_catus
    WHERE  mcv_mc_mc_id = 'DUMP_NO'
    ORA-00904: "MCV_MC_MC_ID": invalid identifier
    SQL> desc dw_mmg_cat_us
    Name         Type         Nullable Default Comments                                                        
    MCV_MC_MC_ID VARCHAR2(10)                  Merchandise category                                            
    MCV_MCV_ID   VARCHAR2(10)                  The value for the category                                      
    MMG_MMGL_ID  NUMBER(3)                     The unique identifier of the MMGL                               
    MMG_MMG_ID   VARCHAR2(10)                  The identifier of the MMG, unique within the significant level  
    DW_EFTV_FROM DATE                          Date the relationship was effective from No direct mapping from 
    DW_EFTV_TO   DATE         Y                Date the relationship is effective to No direct mapping from exi
    SQL> select * from merc_mmg_catus where rownum < 5;
    MMG_ART_MMG_ID MC_MC_ID   MCV_MCV_ID
                12 CLASSTYPE  O
                13 CLASSTYPE  O
                14 CLASSTYPE  O
                15 CLASSTYPE  O
    SQL>
    SQL> SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
      2  FROM   merc_mmg_catus
      3  WHERE  mcv_mc_mc_id = 'DUMP_NO'
      4  /
    SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
    FROM   merc_mmg_catus
    WHERE  mcv_mc_mc_id = 'DUMP_NO'
    ORA-00904: "MCV_MC_MC_ID": invalid identifierHere merc_mmg_catus is the synonym it is not a table? But this object does not have mcv_mc_mc_id,mmg_mmg_id
    these two field so why the above update statement is not failing. if i separately select this query it throws error as above.. then why this is not throwing in the update statement.
    Thanks,
    Sid

    >
    SQL>   UPDATE dw_mmg_cat_us
      2    SET    dw_eftv_to = TRUNC(sysdate)
      3    WHERE  (mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id) IN
      4           (SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
      5           FROM   dw_mmg_cat_us
      6           WHERE  dw_eftv_to is null
      7           AND    mcv_mc_mc_id = 'DUMP_NO'
      8           MINUS
      9           SELECT mcv_mc_mc_id,mcv_mcv_id,mmg_mmg_id
    10           FROM   merc_mmg_catus
    11          WHERE  mcv_mc_mc_id = 'DUMP_NO');When resolving names that have no prefix, Oracle will have to try and figure out what you mean.
    The column names in line 9 have no prefix, so Oracle will try to figure it out.
    It will check if the columns come from the table(s) in the from clause (line 10), as that is not the case it can find the column names in the table in line 1.
    So I think it has resolved the names to be like this:
    SQL>   UPDATE dw_mmg_cat_us d3
      2    SET    d3.dw_eftv_to = TRUNC(sysdate)
      3    WHERE  (d3.mcv_mc_mc_id,d3.mcv_mcv_id,d3.mmg_mmg_id) IN
      4           (SELECT d1.mcv_mc_mc_id,d1.mcv_mcv_id,d1.mmg_mmg_id
      5           FROM   dw_mmg_cat_us d1
      6           WHERE  d1.dw_eftv_to is null
      7           AND    d1.mcv_mc_mc_id = 'DUMP_NO'
      8           MINUS
      9           SELECT d3.mcv_mc_mc_id,d3.mcv_mcv_id,d3.mmg_mmg_id
    10           FROM   merc_mmg_catus d2
    11          WHERE  d2.mcv_mc_mc_id = 'DUMP_NO');Which doesn't make much sense, but is syntactically valid.
    If you make a habit of prefixing column names, you would probably have written something like:
    SQL>   UPDATE dw_mmg_cat_us d3
      2    SET    d3.dw_eftv_to = TRUNC(sysdate)
      3    WHERE  (d3.mcv_mc_mc_id,d3.mcv_mcv_id,d3.mmg_mmg_id) IN
      4           (SELECT d1.mcv_mc_mc_id,d1.mcv_mcv_id,d1.mmg_mmg_id
      5           FROM   dw_mmg_cat_us d1
      6           WHERE  d1.dw_eftv_to is null
      7           AND    d1.mcv_mc_mc_id = 'DUMP_NO'
      8           MINUS
      9           SELECT d2.mcv_mc_mc_id,d2.mcv_mcv_id,d2.mmg_mmg_id
    10           FROM   merc_mmg_catus d2
    11          WHERE  d2.mcv_mc_mc_id = 'DUMP_NO');Which would have failed because Oracle could see that d2 does not have those columns.

  • Group by Query not giving desired results

    Hi,
    I've a requirement to find minimum month based on status:
    The following query is giving error :
    SELECT
              b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
              MIN(a.period_name)
    FROM     table a,
         table b
    WHERE     a.app_id     =     b.app_id
    AND          b.app_name      =     'NAME1'
    AND          a.book_id     =     &book_id
    AND          a.status      =      'O'
    GROUP BY      b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
    for ex: in the above query if I've four records with status 'O' and period_name as 'May-12', 'Jun-12','Jul-12' ,'Aug-12' then I need to pick 'May'
    Thanks,
    Kiran

    Hi, Kiran,
    user518071 wrote:
    Hi,
    I've a requirement to find minimum month based on status:
    The following query is giving error :
    SELECT
              b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
              MIN(a.period_name)
    FROM     table a,
         table b
    WHERE     a.app_id     =     b.app_id
    AND          b.app_name      =     'NAME1'
    AND          a.book_id     =     &book_id
    AND          a.status      =      'O'
    GROUP BY      b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
    for ex: in the above query if I've four records with status 'O' and period_name as 'May-12', 'Jun-12','Jul-12' ,'Aug-12' then I need to pick 'May'
    Thanks,
    KiranIt looks like you're almost there.
    If period_name is a DATE, then
    MIN (a.period_name)is finidng the earliest period name, such as 5 May 2012 17:03:49. If you just want to see 'May 2012', then change that to
    TO_CHAR ( MIN (a.period_name)
            , 'Mon YYYY'
            )If a.period_name is a VARCHAR2, then change it to a DATE. The best way to do this is permanently. There is no reason to store date information in VARCHAR2 columns. Oracle supplies DATE columns; there's no extra cost for using them. DATE columns were designed for storing date information, use them to do that.
    if you must keep your date information in VARCHAR2 a column, then use TO_DATE in the query. It will be slow, and you'll have run-time errors if any of the information is in the wrong format. That's what happens when you store date information in VARCHAR2 columns.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Sql query problem which causes crystal reports in visual studio to freeze

    Anyone know why this query posted here freezes up? if i remove  s.enddate IS NULL from the query is when it freezes up. This is used on an infinite campus database for which i only have read only access so no posting anything that requires write access please!
    IT may just be a flaw in my query which it has been before but it only stops responding if i remove the above query and it only started this after i added the comments subreport if i remove it then the action above doesn't cause it to freeze in visual studio.
    I do have a subreport for comments that is in the report too. Heres the main query:
    SELECT Distinct sc.name,sc.address,sc.city,sc.state,sc.zip,sc.phone,gt.name AS Task, ca.StartDate,
    ca.EndDate, s.lastname','s.firstname AS Student, s.studentnumber,e.grade,t.name AS Term,
    gs.score AS [Current Grade],cg.Cumgpa AS GPA,c.name '-'c.number As Course, se.teacherdisplay,gs.personid,
    MAX(CASE WHEN hl.enddate IS NULL AND ccs.guardian = 1 AND ccs.relatedBy = 'Household' AND ccs.mailing = 1 THEN ccs.addressline1 END) AS AddressLine1,
    MAX(CASE WHEN hl.enddate IS NULL AND ccs.guardian = 1 AND ccs.relatedBy = 'Household' AND ccs.mailing = 1 THEN ccs.addressline2 END) AS [City/State],gs.personid
    FROM GradingScore gs
    LEFT JOIN dbo.student s ON s.personid = gs.personid
    JOIN v_CensusContactSummary ccs ON ccs.personid = s.personid
    JOIN dbo.enrollment e ON e.enrollmentid = s.enrollmentid AND e.calendarid = gs.calendarid
    LEFT JOIN dbo.Term t ON t.termid = gs.termid
    JOIN dbo.section se ON se.sectionid = gs.sectionid
    JOIN v_CumGPA cg on cg.personID = s.personID aND cg.calendarID = s.calendarID
    JOIN gradingtask gt ON gt.taskid = gs.taskID
    JOIN dbo.course c ON c.courseid = se.courseid
    JOIN dbo.roster r ON r.sectionid = se.sectionid
    JOIN calendar ca ON ca.calendarID = gs.calendarID
    JOIN School sc ON sc.schoolID = ca.schoolid
    LEFT JOIN householdlocation hl ON hl.householdid = ccs.householdid
    --Change Term Name to match term name needed or if in a report turn it into a Parameter
    WHERE s.enddate IS NULL AND gs.calendarID IN
    (select calendarid
    from dbo.calendar c
    JOIN dbo.schoolyear sy on sy.endyear = c.endyear
    WHERE  c.schoolID = 2)
    GROUP BY s.studentnumber,s.lastname, s.firstname,e.grade, t.name, gt.name, gs.score, cg.cumgpa, c.name, c.number, se.teacherdisplay, ca.startDate, ca.enddate,
    sc.name, sc.address, sc.city, sc.state, sc.zip, sc.phone,gs.personid
    order by [student],[Term],[Course]
    Edited by: jeffman2 on Oct 6, 2011 3:40 PM
    Edited by: jeffman2 on Oct 6, 2011 3:41 PM
    Edited by: jeffman2 on Oct 6, 2011 3:53 PM
    Edited by: jeffman2 on Oct 6, 2011 3:56 PM
    Edited by: jeffman2 on Oct 6, 2011 3:56 PM

    What happens if you try
    SELECT Distinct sc.name,sc.address,sc.city,sc.state,sc.zip,sc.phone,gt.name AS Task, ca.StartDate,
    ca.EndDate, s.lastname+','+s.firstname AS Student, s.studentnumber,e.grade,t.name AS Term,
    gs.score AS Current Grade,cg.Cumgpa AS GPA,c.name +'-'+c.number As Course, se.teacherdisplay,gs.personid,
    MAX(CASE WHEN hl.enddate IS NULL AND ccs.guardian = 1 AND ccs.relatedBy = 'Household' AND ccs.mailing = 1 THEN ccs.addressline1 END) AS AddressLine1,
    MAX(CASE WHEN hl.enddate IS NULL AND ccs.guardian = 1 AND ccs.relatedBy = 'Household' AND ccs.mailing = 1 THEN ccs.addressline2 END) AS City/State,gs.personid
    FROM GradingScore gs
    LEFT JOIN dbo.student s ON s.personid = gs.personid
    JOIN v_CensusContactSummary ccs ON ccs.personid = s.personid
    JOIN dbo.enrollment e ON e.enrollmentid = s.enrollmentid AND e.calendarid = gs.calendarid
    LEFT JOIN dbo.Term t ON t.termid = gs.termid
    JOIN dbo.section se ON se.sectionid = gs.sectionid
    JOIN v_CumGPA cg on cg.personID = s.personID aND cg.calendarID = s.calendarID
    JOIN gradingtask gt ON gt.taskid = gs.taskID
    JOIN dbo.course c ON c.courseid = se.courseid
    JOIN dbo.roster r ON r.sectionid = se.sectionid
    JOIN calendar ca ON ca.calendarID = gs.calendarID
    JOIN School sc ON sc.schoolID = ca.schoolid
    join (select calendarid
           from dbo.calendar c
           JOIN dbo.schoolyear sy on sy.endyear = c.endyear
           WHERE c.schoolID = 2) ci
           on  gs.calendarID  = ci.calendarid
    LEFT JOIN householdlocation hl ON hl.householdid = ccs.householdid
    --Change Term Name to match term name needed or if in a report turn it into a Parameter
    --WHERE s.enddate IS NULL
    GROUP BY s.studentnumber,s.lastname, s.firstname,e.grade, t.name, gt.name, gs.score, cg.cumgpa, c.name, c.number, se.teacherdisplay, ca.startDate, ca.enddate,
    sc.name, sc.address, sc.city, sc.state, sc.zip, sc.phone,gs.personid
    order by student,Term,Course
    Ian

Maybe you are looking for

  • Creation of sales order with reference - Zfields in Add data B are not cop

    Hi all,           Please help me in the issue . I am creating sales order with reference to returns order . All item fields are getting copied but the Zfields which are added in addtional data b of sales order are not getting copied. Can anyone pleas

  • Preview crashes whenever I try to save a change

    I am getting sick and tired of this--I have religiously sent in the so-called "reports" to apple every time this happens. No sign of a fix. I have had Leopard a couple of months now, and I used to use (pre leopard) preview for making all kinds of ima

  • Need pl/sql stmnts. for this simple logic

    Hi, I need PL/SQL program for this simple logic i am doing mistake somewhere unbale to trace out .. select * from GSR03_PO_DTL; PO_NUM L53177000 -- > no changes reqd (only one entry with new format) L00041677 --> to be updated to L41677000(only one e

  • Forms 6i error FRM-41351 Cannot navigate out of current form

    Does anybody know why this error occurs? I have an ordinary Forms 6i module, running in 2-tier (client-server) mode. When I try to do an EXIT_FORM, I get an error: "FRM-41351: Cannot navigate out of current form" My form is called from a top-level fo

  • Xbench Crashes on Mac Pro 2009

    Hi, I was running Xbench (http://www.xbench.com/) on the new Mac Pro to see how it stacked against the old generation and I found it quite weird that it crashed every 1 out of 3-4 times (sometimes even more often). So I've tried running Xbench on my