Where clause in COUNT function and joining two queries

I have a table that I am trying to count the number of course passed, and also list the modules passed as well.
the first problem I am having is what to put in the where variable , so that its not specific to a customer(I can use the query below for a particular customer and a particular course)but I will like a generic query where the result will be distinct in terms
of user and course like the one below
select FirstName,LastName,CourseTitle,Noofmodules, count (Coursecompleted) as modulescompleted from EStudentsprogress where Coursecompleted = '1'and EmailAddress = '[email protected]'
and CourseTitle = 'Microsoft MOS 2010 EXCEL' Group by FirstName, LastName, CourseTitle, Noofmodules ;
How can i make it list the result as above, whereby i dont specify the email address or course title(trying to get the result for all the clients )
. Also I have a query that list the courses that is passed by the customer, I will like the column with the list of courses passed be added to the result above, but as a column for each course.
select FirstName,LastName,CourseTitle, EmailAddress, CourseModule as coursepassed from EStudentsprogress where coursecompleted =1
cheers

Do you mean this?
select FirstName,
LastName,
CourseTitle,
Noofmodules,
count (Coursecompleted) as modulescompleted,
STUFF((SELECT ',' + CourseTitle
FROM EStudentsprogress
WHERE FirstName = e.FirstName
AND LastName = e.LastName
WHERE Coursecompleted = '1'
FOR XML PATH('')),1,1,'') AS CoursesCompleted
from EStudentsprogress e
where Coursecompleted = '1'
Group by FirstName, LastName, CourseTitle, Noofmodules ;
If not please provide some sample data and explain the output you want
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page
I AM HAVING Incorrect syntax near the keyword 'WHERE'. 
It was a typo
try this
select FirstName,
LastName,
CourseTitle,
Noofmodules,
count (Coursecompleted) as modulescompleted,
STUFF((SELECT ',' + CourseTitle
FROM EStudentsprogress
WHERE FirstName = e.FirstName
AND LastName = e.LastName
AND Coursecompleted = '1'
FOR XML PATH('')),1,1,'') AS CoursesCompleted
from EStudentsprogress e
where Coursecompleted = '1'
Group by FirstName, LastName, CourseTitle, Noofmodules ;
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page
its populating all the result for a particular customer, so i added another clause to  it and it worked
select FirstName,
LastName,
CourseTitle,
Noofmodules, 
count (Coursecompleted) as modulescompleted,
STUFF((SELECT ','  + CourseTitle
FROM EStudentsprogress 
WHERE FirstName = e.FirstName
AND LastName = e.LastName
AND Coursecompleted = '1'
AND CourseTitle = e.CourseTitle
FOR XML PATH('')),1,1,'') AS CoursesCompleted
from EStudentsprogress e
where Coursecompleted = '1'
Group by FirstName, LastName, CourseTitle, Noofmodules ;
but the result of the column is long , so i tried to used the course module, which is a column with numbers, and i tried modifying the query , but i had Error converting data type varchar to float.( i checked and saw that stuff is for concatinating
strings) is there a way around it.
i used 
select FirstName,
LastName,
CourseModule,
CourseTitle,
Noofmodules, 
count (Coursecompleted) as modulescompleted,
STUFF((SELECT ','  + CourseModule
FROM EStudentsprogress 
WHERE FirstName = e.FirstName
AND LastName = e.LastName
AND Coursecompleted = '1'
AND CourseTitle = e.CourseTitle
FOR XML PATH('')),1,1,'') AS CoursesCompleted
from EStudentsprogress e
where Coursecompleted = '1'
Group by FirstName, LastName,CourseModule, CourseTitle, Noofmodules ;

Similar Messages

  • Join two queries

    I'm tryinng to join two queries that I made in sqlplus:
    the first one is:
    select dname,sum(hours) as proj_hrs
    from IBL.works_on w ,IBL.project p,IBL.department d
    where w.pno=p.pnumber
    and p.dnum=d.dnumber
    group by dname;
    that output:
    DNAME PROJ_HRS
    Administration 115
    Headquarters 25
    Research 155
    the second one is:
    select dname,sum(hours) as emp_hrs
    from IBL.works_on w,IBL.employee e,IBL.department d
    where e.dno=d.dnumber
    and w.essn=e.ssn
    group by dname;
    that output
    DNAME EMP_HRS
    Administration 115
    Headquarters
    Research 180
    I'm trying to join both of them to get:
    DNAME PROJ_HRS EMP_HRS
    Administration 115 115
    Headquarters 25
    Research 155 180
    Can anybody help me please

    If I understood you correctly, have you tried this? I did not try this, just think that it will work.
    select a.dname, a.proj_hrs, b.emp_hrs from
    select dname,sum(hours) as proj_hrs
    from IBL.works_on w ,IBL.project p,IBL.department d
    where w.pno=p.pnumber
    and p.dnum=d.dnumber
    group by dname
    ) a,
    select dname,sum(hours) as emp_hrs
    from IBL.works_on w,IBL.employee e,IBL.department d
    where e.dno=d.dnumber
    and w.essn=e.ssn
    group by dname
    ) b
    where a.dname = b.dname
    You can use the NVL function to print out something special for the null values.

  • Joining two queries with Visual Composer

    Hallo,
    I was working with visual composer to join two queries with the distinct operator. But on my table view, when i linked it with the distinct operator, i get only the key element customer (customer, customer_ext_key, customer_key). These are the queries that i want join:
    Query 1:
    Customer
    Net Sales
    Query 2:
    Customer
    Billed Quantity
    What i want to see is the following result:
    Customer
    Net Sales
    Billed Quantity
    Can anybody help me with this problem?
    Greeting,
    Murat.

    Hallo,
    I was working with visual composer to join two queries with the distinct operator. But on my table view, when i linked it with the distinct operator, i get only the key element customer (customer, customer_ext_key, customer_key). These are the queries that i want join:
    Query 1:
    Customer
    Net Sales
    Query 2:
    Customer
    Billed Quantity
    What i want to see is the following result:
    Customer
    Net Sales
    Billed Quantity
    Can anybody help me with this problem?
    Greeting,
    Murat.

  • WHERE clause comparing count and RowNumber

    Hello, I have just one more question with an error I'm running into. I'm wanting to use a WHERE or HAVING (tried both) to filter the returned data to be between a calculated RowNumber. I tried setting the filter on the tablix or using variables but neither
    one worked.I had some help getting the RowNumbers to work now I'm hoping to use that RowNumber to filter the data to only show the data in the middle 80* of what is returned. So what I'm trying to do is use count to find total number of rows. Then filter out
    the both 10% and top 90& using that count and then filtered on the RowNumbers.
    I tried using different syntax of WHERE and HAVING and I tried putting those clauses under the first WHERE clause or by itself outside of the second select (shown in the example now below). Nothing I've tried works. Is what I'm trying to do possible or is
    there another way I could do this if not?
    Thanks for the help, much appreciated!
    SELECT *,ROW_NUMBER() OVER (ORDER BY TTR) AS RowNumber FROM (
    SELECT
    FilteredIncidentResolution.incidentid,
    FilteredIncident.createdon,
    FilteredIncidentResolution.actualend,
    FilteredIncident.statecodename,
    FilteredIncident.casetypecodename,
    FilteredIncidentResolution.timespent,
    DATEDIFF(minute, FilteredIncident.createdon, FilteredIncidentResolution.actualend) as TTR
    FROM FilteredIncident INNER JOIN
    FilteredIncidentResolution ON FilteredIncident.incidentid = FilteredIncidentResolution.incidentid
    WHERE (FilteredIncident.statecodename = N'Resolved') AND (FilteredIncident.casetypecodename = N'Support') AND (FilteredIncidentResolution.actualend >= @start) AND
    (FilteredIncidentResolution.actualend <= @end)
    ) X
    WHERE RowNumber >= count(FilteredIncidentResolution.incidentid)*.1 AND RowNumber <= count(FilteredIncidentResolution.incidentid)*.9
    ORDER BY TTR

    You're making the same mistake as before. Calculated column can not be used in the WHERE clause. I think you're actually looking for the NTILE() function, but I will just fix your query:
    select * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY TTR) AS RowNumber FROM (
    SELECT
    FilteredIncidentResolution.incidentid,
    FilteredIncident.createdon,
    FilteredIncidentResolution.actualend,
    FilteredIncident.statecodename,
    FilteredIncident.casetypecodename,
    FilteredIncidentResolution.timespent,
    DATEDIFF(minute, FilteredIncident.createdon, FilteredIncidentResolution.actualend) as TTR,
    COUNT(FilteredIncidentResolution.incidentid)
    OVER() as TotalIncidents
    FROM FilteredIncident INNER JOIN
    FilteredIncidentResolution ON FilteredIncident.incidentid = FilteredIncidentResolution.incidentid
    WHERE (FilteredIncident.statecodename = N'Resolved') AND (FilteredIncident.casetypecodename = N'Support') AND (FilteredIncidentResolution.actualend >= @start) AND
    (FilteredIncidentResolution.actualend <= @end)
    ) X
    ) Y
    WHERE RowNumber >= TotalIncidents*.1 AND RowNumber <= TotalIncidents*.9 -- we're excluding top 10 and bottom 10
    ORDER BY TTR
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Where clause on one column out of two

    I have a where clause filtering out data from the sum(workhour) column. I want to return another column beside it that does not filter workhour and a third column that filters workhour based on a different criteria. Is this possible?
    sql
    select activity_exit_date.year_id, activity_exit_date.month_id, locked_by, round(sum(workhour*60),1) as 'Maker/Checker Time'
    from activity_exit_date
    right join (project_name right join time_tracking on project_name.projectname_id=time_tracking.projectname_id)
    on Activity_Exit_Date.Activity_Exit_Date=time_tracking.Activity_Exit_Date
    where projectname like '%Maker%'
    group by activity_exit_date.year_id, activity_exit_date.month_id, locked_by
    year month locked_by maker/checker
    2     2.0     aa93971     9316.2
    2     2.0     ab41741     330.0
    2     2.0     ab48799     8068.8
    2     2.0     ag27219     7230.0
    2     2.0     ah96254     7216.2
    2     2.0     ah96763     6180.0
    2     2.0     aj58427     1170.0
    2     2.0     ak27324     7596.0
    2     2.0     am37564     2790.0
    2     2.0     ar04163     9885.0
    2     2.0     as03789     9492.0
    2     2.0     av04089     4854.0
    2     2.0     aw03010     10056.6
    thanks!
    J

    Hi,
    Conditions in the WHERE clause affect the entire result set.
    If you want certain conitions only to apply to certain columns, then put the condition in a CASE expression.
    For example:
    SELECT       deptno
    ,       COUNT (*)          AS total_cnt
    ,       COUNT ( CASE
                     WHEN  job = 'CLERK'
                   THEN  1
                  END
                )          AS clerk_count
    ,       COUNT ( CASE
                     WHEN  sal > 1000
                   THEN  1
                  END
                )          AS sal_1000_cnt
    FROM      scott.emp
    GROUP BY  deptno;Output:
        DEPTNO  TOTAL_CNT CLERK_COUNT SAL_1000_CNT
            30          6           1            5
            20          5           2            4
            10          3           1            3Note that these are the same numbers we would get by running these queries separately:
    SELECT  deptno, COUNT (*) FROM scott.emp                  GROUP BY deptno;
    SELECT  deptno, COUNT (*) FROM scott.emp WHERE job = 'CLERK' GROUP BY deptno;
    SELECT  deptno, COUNT (*) FROM scott.emp WHERE sal > 1000    GROUP BY deptno; 
    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 (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Generating a 'WHERE' clause using a function

    Hi I have below requirement,
    for given function below are input parameters,
    sk_func(salary,dept_no,job,hire_date)
    which ever input is given those inputs should be there in one statement,
    For example if I give input as
    select sk_func(5000,null,null,null) from dual;
    I need output as Where salary=5000;
    if I give input as
    select sk_func(5000,null,'Programmer',null) from dual;
    I need output as Where Salary=5000 and job='Programmer';
    Hope am clear,
    In short which ever values are not null, those all should include in my where clause,
    I know how to do it, but taking into considerations, am finding the best way to do it,
    Thanks for your responses,

    Hi Karthik,
    this is the api, I have done,
    create or replace
    FUNCTION get_where_clause_for_emp_req (
       emp_id       IN   NUMBER,
       salary            IN   NUMBER,
       job         IN   VARCHAR2,
       dept IN NUMBER
       RETURN VARCHAR2
    IS
       l_where_clause   VARCHAR2 (2000);
    BEGIN
       IF (    (emp_id IS NULL)
           AND (salary IS NULL)
           AND (job IS NULL)
           AND (deptIS NULL)
       THEN
          RETURN NULL;
       ELSE
          l_where_clause := 'WHERE ';
       END IF;
       IF (emp_id IS NOT NULL)
       THEN
          l_where_clause :=
                        l_where_clause || ' emp_id =' || emp_id || '';
       END IF;
       IF ((emp_id IS NOT NULL) AND (salary IS NOT NULL))
       THEN
          l_where_clause :=
                          l_where_clause || ' AND salary= ' || salary;
       ELSIF (salary IS NOT NULL)
       THEN
          l_where_clause := l_where_clause || ' salary= ' || salary;
       END IF;
       IF (((salary IS NOT NULL) AND (dept IS NOT NULL)) OR ((emp_id IS NOT NULL) AND (salary IS NULL) AND (dept IS NOT NULL)))
       THEN
          l_where_clause := l_where_clause || ' AND dept= ' || dept;
       ELSIF (status_i IS NOT NULL)
       THEN
          l_where_clause := l_where_clause || ' dept= ' || dept;
       END IF;
    l_where_clause := l_where_clause || ' ;';
       RETURN l_where_clause;
    END;I have done for three parameters, i need to include two more input parameters for this function, so I see going forward my testing cases will increases,
    so am looking for the best solution
    Thanks
    Edited by: NSK2KSN on Jul 7, 2010 3:11 PM

  • SQL Where clause when comparing dates and times in ASP

    Hello,
    I am trying to pull data from my database which is dependant on both the date and time in HH24 format. So, my where clause looks something like this:
    select * from thisTable where activity_time >= myCurrentDate
    (myCurrentDate is a variable that is built which gives it the following format DD-MON-YYYY HH24:MI:SS)
    So, the actual passed string to my call is:
    select * from thisTable where ACTIVITY_TIME >= '02-DEC-2008 18:22:00' order by ACTIVITY_TIME asc
    However, when calling this, I get the famous "ORA-01830: date format picture ends before converting entire input string"
    Can anyone please help me?!?!?!?
    Thanks in advance

    Enrique answered your immediate question, but I'd like to point up a broader issue, and that is that you should <b><u>always</u></b> use the TO_DATE and TO_CHAR functions at the sql statement level when working with date datatypes. That way you are never dependent on some default over which you have no control. I call that is 'defensive coding'.

  • Nested Count function and substring... Need some tips.tx

    I am trying to find out the number of active students who have the course 'MCB4U'
    twice on their records.
    Please let me a comment if you know the solution.
    Thank you
    Here is my code:
    SELECT COUNT(*)
    FROM PROG A, ENRL B
    WHERE A.STUID = B.STUID
    AND B.ENRL = 'E'
    AND A.STATUS ='ACTIVE'
    AND B.TERM = '2007'
         AND EXISTS (SELECT COUNT(E.SCHOOL_NBER)
                        FROM EXT_COURSE C, EXT_CRSE D, PS_SCHOOL_CRSE E
                                  WHERE C.STUID = D.STUID
                                  AND C.EXT_ID = D.EXT_ID
                                  AND C.COURSE_NBR = D.COURSE_NBR
                                  AND D.EXT_ID = E.EXT_ID
                                  AND E.SCHOOL_SUBJECT = D.SCHOOL_SUBJECT
                                  AND E.SCHOOL_NBR = D.SCHOOL__NBR
                                  AND E.SCHOOL_NBR SUBSTR ('MCB4',5,1)
                                  AND D.EMPLID = A.EMPLID
                                  HAVING COUNT(*) > 2)
    HAVING COUNT(*)=1 -- This statement identifies the distinct enroled students

    I don't have your tables, but in general if you want "the number of active students who have the course 'MCB4U' twice on their records", then your query might look like this:
    select count(*)
      from ( select count(*)
               from ...
              where ...
              group by stuid
             having count(*) = 2
           )Regards,
    Rob.

  • Joining two queries causes big performance hit

    There are two queries: one with a sub query and one without
    although they both return the same data, one uses a full table scan of the indexed 'trade_index' table
    and thus is much slower
    any Ideas why it does this?:
    SQL> select count(*) from trade_index ti, counterparty_xref cx
    2 where ti.CPY_SID = cx.CPY_SID and ti.TRADE_OR_ARCHIVE = 'A'
    3 and cx.XREF_VALUE in (select ml.VALUE from v_mis_lists ml where ml.LIST_NAME = 'Deutsche Bank DB')
    4 and cx.XREF_TYPE = 'Client RXM'
    5 and ti.START_DATE < to_date('01/01/2004','DD/MM/YYYY')
    6 and (ti.END_DATE >= to_date('01/01/2003','DD/MM/YYYY') or ti.END_DATE = '01-Jan-1900') ;
    COUNT(*)
    6195
    Elapsed: 00:00:15.08
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2572 Card=1 Bytes=57)
    1 0 SORT (AGGREGATE)
    2 1 HASH JOIN (Cost=2572 Card=26581 Bytes=1515117)
    3 2 HASH JOIN (Cost=460 Card=5619 Bytes=219141)
    4 3 VIEW OF 'VW_NSO_1' (Cost=8 Card=16 Bytes=272)
    5 4 SORT (UNIQUE) (Cost=8 Card=16 Bytes=960)
    6 5 HASH JOIN (Cost=4 Card=16 Bytes=960)
    7 6 TABLE ACCESS (BY INDEX ROWID) OF 'MIS_LISTS' (Cost=1 Card=2 Bytes=60)
    8 7 INDEX (RANGE SCAN) OF 'MISL_NAT_UK' (UNIQUE) (Cost=2 Card=2)
    9 6 TABLE ACCESS (FULL) OF 'MIS_LIST_VALUES' (Cost=2 Card=817 Bytes=24510)
    10 3 TABLE ACCESS (FULL) OF 'COUNTERPARTY_XREF' (Cost=451 Card=35116 Bytes=772552)
    11 2 TABLE ACCESS (FULL) OF 'TRADE_INDEX' (Cost=2056 Card=286928 Bytes=5164704)
    SQL> select ml.VALUE from v_mis_lists ml where ml.LIST_NAME = 'Deutsche Bank DB';
    VALUE
    B49540
    B60010
    Elapsed: 00:00:00.00
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 NESTED LOOPS
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'MIS_LISTS'
    3 2 INDEX (RANGE SCAN) OF 'MISL_NAT_UK' (UNIQUE)
    4 1 INDEX (RANGE SCAN) OF 'MISLV_PK' (UNIQUE)
    SQL> select count(*) from trade_index ti, counterparty_xref cx
    2 where ti.CPY_SID = cx.CPY_SID and ti.TRADE_OR_ARCHIVE = 'A'
    3 and cx.XREF_VALUE in ('B49540','B60010')
    4 and cx.XREF_TYPE = 'Client RXM'
    5 and ti.START_DATE < to_date('01/01/2004','DD/MM/YYYY')
    6 and (ti.END_DATE >= to_date('01/01/2003','DD/MM/YYYY') or ti.END_DATE = '01-Jan-1900') ;
    COUNT(*)
    6195
    Elapsed: 00:00:02.06
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=532 Card=1 Bytes=40)
    1 0 SORT (AGGREGATE)
    2 1 NESTED LOOPS (Cost=532 Card=41 Bytes=1640)
    3 2 TABLE ACCESS (FULL) OF 'COUNTERPARTY_XREF' (Cost=451 Card=1 Bytes=22)
    4 2 TABLE ACCESS (BY INDEX ROWID) OF 'TRADE_INDEX' (Cost=81 Card=286928 Bytes=5164704)
    5 4 INDEX (RANGE SCAN) OF 'CPY_SID_IDX' (NON-UNIQUE) (Cost=2 Card=286928)
    What I dont understand is that:
    cx.XREF_VALUE in (select ml.VALUE from v_mis_lists ml where ml.LIST_NAME = 'Deutsche Bank DB')
    and
    cx.XREF_VALUE in ('B49540','B60010')
    are essentially the same thing
    (ie the subquery returns the values I have used)
    but the optimizer uses a totally different (slower) method to execute the rest of the former query?
    Many thanks
    Ian

    Hi,
    Here is with join and not using the view: still have full table scan of large table trade_index
    SQL> select count(*) from mis_lists ml, mis_list_values mlv, counterparty_xref cx, trade_index ti
    2 where ti.CPY_SID = cx.CPY_SID and ti.TRADE_OR_ARCHIVE = 'A'
    3 and cx.XREF_VALUE = mlv.VALUE
    4 and mlv.MISL_SID = ml.MISL_SID
    5 and ml.LIST_NAME = 'Deutsche Bank DB'
    6 and cx.XREF_TYPE = 'Client RXM'
    7 and ti.START_DATE < to_date('01/01/2004','DD/MM/YYYY')
    8 and (ti.END_DATE >= to_date('01/01/2003','DD/MM/YYYY') or ti.END_DATE = '01-Jan-1900') ;
    COUNT(*)
    6195
    Elapsed: 00:00:12.08
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2602 Card=1 Bytes=10
    0)
    1 0 SORT (AGGREGATE)
    2 1 HASH JOIN (Cost=2602 Card=26581 Bytes=2658100)
    3 2 HASH JOIN (Cost=456 Card=5619 Bytes=460758)
    4 3 HASH JOIN (Cost=4 Card=16 Bytes=960)
    5 4 TABLE ACCESS (BY INDEX ROWID) OF 'MIS_LISTS' (Cost1 Card=2 Bytes=60)
    6 5 INDEX (RANGE SCAN) OF 'MISL_NAT_UK' (UNIQUE) (Cost=2 Card=2)
    7 4 TABLE ACCESS (FULL) OF 'MIS_LIST_VALUES' (Cost=2 Card=817 Bytes=24510)
    8 3 TABLE ACCESS (FULL) OF 'COUNTERPARTY_XREF' (Cost=451Card=35116 Bytes=772552)
    9 2 TABLE ACCESS (FULL) OF 'TRADE_INDEX' (Cost=2056 Card=286928 Bytes=5164704)
    Statistics
    0 recursive calls
    47 db block gets
    16519 consistent gets
    4981 physical reads
    0 redo size
    205 bytes sent via SQL*Net to client
    622 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    Thanks for you help,
    Ian

  • How to join two queries

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    _1st query_
    select
    (CASE WHEN SUBSTR(R1.RA_NO,1,3)= 'NRA' THEN 'Damansara Uptown One Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,3)= 'ORA' THEN 'Damansara Uptown Two Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,3)= 'VRA' THEN 'Damansara Uptown Realty Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,3)= 'URA' THEN 'Uptown Elite Sdn. Bhd.'
    when SUBSTR(R1.RA_NO,1,3)= 'WRZ' THEN 'U5 Management Corporation Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,2)= 'FR' THEN 'See Hoy Chan Facilities Management Sdn.Bhd.' END) Landlord
    ,TO_CHAR(C1.COLL_DTE,'RRRRMM') MONTH1
    ,SUM(C2.TRN_AMT) UPTO_31
    , SUM(CASE WHEN to_char(C1.COLL_dte) BETWEEN to_date(:P_FROM_DATE,'dd.mm.yyyy') AND '16-'||to_date(:P_TO_DATE,'dd.mm.yyyy') THEN C2.TRN_AMT END) UPTO_15
    from ra1 R1, COLLECT1 C1 , COLLECT2 C2
    where
    (to_char(C1.COLL_dte) between to_date(:P_FROM_DATE,'dd.mm.yyyy') AND to_date(:P_TO_DATE,'dd.mm.yyyy'))
    and (SUBSTR(R1.RA_NO,1,2)= 'FR' or SUBSTR(R1.RA_NO,1,3) in ('NRA' ,'ORA','VRA','URA','WRZ'))
    AND R1.RA_NO = C2.INV_NO
    AND C2.COLL_NO = C1.COLL_NO
    GROUP BY
    (CASE WHEN SUBSTR(R1.RA_NO,1,3)= 'NRA' THEN 'Damansara Uptown One Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,3)= 'ORA' THEN 'Damansara Uptown Two Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,3)= 'VRA' THEN 'Damansara Uptown Realty Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,3)= 'URA' THEN 'Uptown Elite Sdn. Bhd.'
    when SUBSTR(R1.RA_NO,1,3)= 'WRZ' THEN 'U5 Management Corporation Sdn. Bhd.'
    WHEN SUBSTR(R1.RA_NO,1,2)= 'FR' THEN 'See Hoy Chan Facilities Management Sdn.Bhd.' END)
    ,TO_CHAR(C1.COLL_DTE,'RRRRMM')
    _2query_
    select sum(decode(substr(ra_no,1,7),'NRA'
    ||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) NRA
    ,sum(decode(substr(ra_no,1,7),'VRA'
    ||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) VRA
    ,sum(decode(substr(ra_no,1,7),'ORA'
    ||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) ORA
    ,sum(decode(substr(ra_no,1,7),'FR'
    ||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) FR
    ,sum(decode(substr(ra_no,1,7),'WRZ'
    ||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) WRZ
    ,sum(decode(substr(ra_no,1,7),'URA'
    ||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) URA
    from RA1
    above are the two queries i need to join these two queries by naming the second query column name as total .

    1st query output  is ----------
    LOCATION                                                                 MONTH1    UPTO_31           UPTO_15        
    U5 Management Corporation Sdn. Bhd.                           201001     15250                8900                                 
    Uptown Elite Sdn. Bhd.                                                201001      3000                 1500                                 
    See Hoy Chan Facilities Management Sdn.Bhd.                 201001      917115.45         584876.5                            
    Damansara Uptown Two Sdn. Bhd.                                201001      757277.45         495362.95                          
    Damansara Uptown One Sdn. Bhd.                                 201001     881558.65          404872.45                          
    Damansara Uptown Realty Sdn. Bhd.                              201001      321675.8           150508.6                              
    2nd query output is -------
    NRA              ORA              VRA              URA              WRZ           FR
    2323.31        95945           34367.8        34267            4343         343
    Now what i need is
    LOCATION                                                                 MONTH1    UPTO_31           UPTO_15          TOTAL
    U5 Management Corporation Sdn. Bhd.                           201001     15250                8900                2323.31                 
    Uptown Elite Sdn. Bhd.                                                201001      3000                 1500                95945                  
    See Hoy Chan Facilities Management Sdn.Bhd.                 201001      917115.45         584876.5           34367.8                  
    Damansara Uptown Two Sdn. Bhd.                                201001      757277.45         495362.95          34267                 
    Damansara Uptown One Sdn. Bhd.                                 201001     881558.65          404872.45           4343
    Damansara Uptown Realty Sdn. Bhd.                              201001      321675.8           150508.6           343above is the clear picture what i need , i don't know how to do it please help me
    Edited by: user9093689 on Feb 21, 2010 8:06 PM

  • Joining two queries

    hi every one...
    i have to prepare report in the following way
    srno asset_code asset_group asset_cost
    here asset code and asset group i have to pick from flex field valueset...fr this the query is
    SELECT FLEX_VALUE asset_code, DESCRIPTION asset_group
    FROM FND_FLEX_VALUES_VL ffvh
    WHERE ffvh.flex_value_set_id =
    (select FLEX_VALUE_SET_ID from fnd_flex_value_sets
    where FLEX_VALUE_SET_NAME = 'XXEAM_ACCOUNT_CODE_KFF')
    AND ENABLED_FLAG = 'Y'
    AND SUMMARY_FLAG = 'Y'
    here the each asset_code has their child values and asset cost to that child value..
    so i have to calculate that total asset cost for total child values of each parent(asset_code)...
    for this the query is
    SELECT sum(asset_cost) asset_cost
    FROM csi_item_instances cii,
    xxeam_depreciation_master xdm
    WHERE cii.serial_number = xdm.serial_number
    AND cii.attribute3 IN (
    SELECT ffvh.flex_value
    FROM fnd_flex_values_vl ffvh
    WHERE ffvh.flex_value_set_id =
    (SELECT flex_value_set_id
    FROM fnd_flex_value_sets
    WHERE flex_value_set_name =
    'XXEAM_ACCOUNT_CODE_KFF')
    AND enabled_flag = 'Y'
    AND summary_flag = 'N'
    AND ffvh.flex_value IN (
    SELECT child_flex_value_low
    FROM fnd_flex_value_norm_hierarchy ffvnh
    WHERE ffvnh.range_attribute = 'C'
    AND ffvnh.flex_value_set_id =
    ffvh.flex_value_set_id
    AND ffvnh.parent_flex_value ='10.100'))
    here instead of mentioning ffvnh.parent_flex_value ='10.100'
    i have to find for all parent values..
    so im not able to find this and im not able to make joins..
    so any one plz help me...
    thanks in advance..

    More or less a stab in the dark, but it sounds like you should cross join the groups and date tables with each other:
    SELECT DATEADD(MONTH,- 1, A.Date_Date)AS Report_Date, GROUP_NAME
                 SELECT COUNT(B.Ticket_ID)AS Active_Ticket_Count
                 FROM [HPSM].[dbo].[HPSM_Assignments] B
                 WHERE   B.Assignment_Scope= 'Group'
                    AND  B.Assigned_Timestamp< A.Date_Date
                    AND  B.Resolved_Timestamp> A.Date_Date   
                    AND  B.Group_Name= G.Assigned_To
          ) AS Active_Count
     FROM [ITSReporting ].[dbo].[REF_Date]A      
     CROSS JOIN [HPSM].[dbo].[HPSM_Groups] G
     WHERE Date_Is_Month_Start= 1
          AND A.Date_Date>= dateadd(ms,- 3,dateadd(mm,- 12,dateadd(mm,datediff(mm,0,getdate()),0)))
          AND A.Date_Date< dateadd(ms,- 3,dateadd(mm,1,dateadd(mm,datediff(mm,0,getdate()),0)))
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Need to join two queries A/R statemet and Activity report

    I have two  separate queries that need to be one. I have an A/R statement where I want to add notes next to each invoice. Currently these are two separate reports. How can I link the activity Report to the A/R Statement. Below are the two separate reports. I am not sure how to join the files. A/R Aging Report Declare @d datetime set @d /*Select 1 from jdt1 t where t.duedate*/=[%1] select * from ( SELECT T1.CardCode, T1.CardName, T0.RefDate, T0.Ref1 'Document Number',     CASE  WHEN T0.TransType=13 THEN 'Invoice'           WHEN T0.TransType=14 THEN 'Credit Note'           WHEN T0.TransType=30 THEN 'Journal'           WHEN T0.TransType=24 THEN 'Receipt'           END AS 'Document Type',     T0.DueDate, (T0.Debit- T0.Credit) 'Balance'     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)=0 and DateDiff(day, T0.DueDate,@d)30 and DateDiff(day, T0.DueDate,@d)60 and DateDiff(day, T0.DueDate,@d)90 and DateDiff(day, T0.DueDate,@d)=121),0) '121+ Days' FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode WHERE  T1.CardType = 'C' ) sub Activity Report SELECT T1.[ClgCode],T2.[U_NAME], T4.[Name] as Status, T0.[CardCode], T0.[CardName], T0.[DocNum], T0.[U_AIS_DVIInvName] as 'SF Invoice Name', (T0.U_AIS_DVISFSO) as 'SO#', T0.[DocDate],T0.Taxdate as 'Month Of Service',T0.[U_AIS_DVIOpptyNm],T0.[U_AIS_DVIAdvNm],T0.[U_AIS_DVIManNm],T0.[U_AIS_DVIAcctNm], T0.[DocTotal], T0.[DocStatus],  T1.[Recontact],  T1.[Details], T1.[Notes], T1.[CntctType], T3.[Name] FROM OINV T0 left join OCLG T1 on t0.docentry = t1.docentry and  T0.[ObjType]  =  T1.[DocType] left outer JOIN OUSR T2 ON T1.UserSign = T2.USERID left outer join OCLT T3 ON T1.CntctType = T3.Code left outer join OCLS T4 ON  T1.CntctSbjct = T4.Code where T1.[CntctType] =6 or T1.[CntctType] =7

    This is what I have so far.. it finally produced results but I notice the amount on the Activity + Aging does not match what is on the Aging and that seems to be what the issue is... that was my check to know the report is working. Basically the report should show the aging + any activity associated with the open invoice. The amount on the report is lower than the aging.. I am attaching the aging query  and the aging with activity Query. It looks like something is not joining correctly as the amounts do not match on the balance. Aging Report Declare @d datetime set @d /*Select 1 from jdt1 t where t.duedate*/=[%1] select * from ( SELECT T1.CardCode, T1.CardName, T0.RefDate, T0.Ref1 'Document Number',     CASE  WHEN T0.TransType=13 THEN 'Invoice'           WHEN T0.TransType=14 THEN 'Credit Note'           WHEN T0.TransType=30 THEN 'Journal'           WHEN T0.TransType=24 THEN 'Receipt'           END AS 'Document Type',     T0.DueDate, (T0.Debit- T0.Credit) 'Balance'     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)=0 and DateDiff(day, T0.DueDate,@d)30 and DateDiff(day, T0.DueDate,@d)60 and DateDiff(day, T0.DueDate,@d)90 and DateDiff(day, T0.DueDate,@d)=121),0) '121+ Days' FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode WHERE  T1.CardType = 'C' ) sub Activity + Aging Declare @d datetime set @d /*Select 1 from jdt1 t where t.duedate*/=[%1] select * from ( SELECT T1.CardCode, T1.CardName, T0.RefDate, T0.Ref1 'Document Number',     CASE  WHEN T0.TransType=13 THEN 'Invoice'           WHEN T0.TransType=14 THEN 'Credit Note'           WHEN T0.TransType=30 THEN 'Journal'           WHEN T0.TransType=24 THEN 'Receipt'           END AS 'Document Type',     T0.DueDate, (T0.Debit- T0.Credit) 'Balance'     ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)=0 and DateDiff(day, T0.DueDate,@d)30 and DateDiff(day, T0.DueDate,@d)60 and DateDiff(day, T0.DueDate,@d)90 and DateDiff(day, T0.DueDate,@d)=121),0) '121+ Days', T6.[FirstName] as 'AP Contact First Name', T6.[LastName] as 'AP Contact Last Name' , T6.[E_MailL], T6.[Notes1] as ' AP Supervisor', T2.[ClgCode],T7.[U_NAME], T4.[Name] as Status, T5.[DocNum], T5.[U_AIS_DVIInvName] as 'SF Invoice Name', (T5.U_AIS_DVISFSO) as 'SO#', T5.[DocDate],T5.Taxdate as 'Month Of Service',T5.[U_AIS_DVIOpptyNm],T5.[U_AIS_DVIAdvNm],T5.[U_AIS_DVIManNm],T5.[U_AIS_DVIAcctNm], T5.[DocTotal], T5.[DocStatus],  T2.[Recontact],  T2.[Details], T2.[Notes], T2.[CntctType], T3.[Name] FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode INNER JOIN OCLG T2 ON T1.CardCode = T2.CardCode INNER JOIN OCLT T3 ON T2.CntctType = T3.Code INNER JOIN OCLS T4 ON T2.CntctSbjct = T4.Code INNER JOIN OINV T5 ON t5.docentry = t2.docentry and  T5.[ObjType]  =  T2.[DocType] left outer join OCPR T6 ON T2.CntctCode = T6.CntctCode left outer JOIN OUSR T7 ON T2.UserSign = T7.USERID WHERE  T1.CardType = 'C' and (T2.[CntctType] =6 or T2.[CntctType] =7) ) sub

  • Combine and Join Two Closed Paths With A Straight Path

    Hi,
    I have two closed path and I need to combine or join them with a straight path. When I selected all and right click to join, it did not join. Please refer to my screen shot. Thank you.

    You can't create Y-junctions.
    You can do one of two possbilities:
    Just place the open path wherever you need and leave it there.
    convert all of the shapes with Object > Path > outline stroke and then use the pathfinder functions.

  • Is there anywhere where Apple describes the function and use of every field and popup and checkbox in the email setup "panes"???

    So you call up an account in email
    Account Information is selecgted in the 3-choice menu-bar/button (what is that thing called, anyway? An "inspector"? (frown).
    Then check "enable this account"--is selectable
    Then Account type: iCloud IMAP or example--this is NOT selectable.
    Then "Description field" What's it for, where does it show up, especially if it shows up in other "related" or "integrated" programs?
    Alias popup: What's this for? How do you use it. What approaches, strategies, effects might one employ?
    Email address is pretty straight forward--but see "user.name" in the "server sub-box/sub-pane" below.
    Full Name:  What full name? Where does it appear in use? I cannot access it from the pane/panel, so how do I set it, or who/what sets it?
    Outgoing mail server (SMTP): OK, here's a popup that isn't congruent with "account type" in the first sub-pane. Or is IMAP only an extroverted function/setting, and (SMTP) is a introverted one (IMAP for outbound, SMTP for inbound)?
    Now comes Confusion: Outgoing Mail Server popup menu, which leads you off to a wholenother pane that lets you create new/delete old incoming server names.
    There's a Description (what's that for, what does it do?  Ditto Server name--I get than's something like smtp.ISP.Com or IMAP.ISP.com). You can set those fields in the + menu Account Information Pane, with its blank text fields. And you can also "double-click to enter" that field in the list itself. Why is that?And then I can select Advanced, and get another batch of checkboxes, fields, and popups.
    But I left the Account Information pane before asking, What is this Thread-Lock Stitching Certificate thing? (Or is that Transport Layer Secrecy Sertificate, what?  None is displaying now, but if I popup what's beneath it a humongously long "ID" string, which I take to be, what, my Apple ID? A public key/ provate key encryption string/key? How do I use it if I'm trying to keep the National Surveillance Agency from eavesdropping, "in the clear," my every blessed keystroke, "phrase-stroke" (think VoIP), and if I use the thing, can the president just press a button and send a drone to blow me off the planet (and anyone near me at the time--always great fun for friends and family)?
    And never mind router and FiOS, etc., modem settings. and the Network settings outside of email....
    I guess my bottom line is, the user is presented with a rich smorgasbord of significant choices by all of the panes and panels, etc., on the mac, iMac, iPad-Phone-Watch real soon now, mac pro, macbook pro, etc.  But the specific description of the proper use of these description/instruction on their use and function is impoverished.  I think manuals used to handle some of these issues. But where are the manuals? Or am I just so overwhelmed by the complexity of what was once a simple user interface that I can't see pointers (in light grey type on lighter grey backgrounds--what the heck is wrong with black type, I'd like to know!) staring me in the phiz. Oh, help.

    Hi Cff7dxp,
    I am glad to hear that your issue has been resolved from the provided troubleshooting steps. Please feel free to post in Lenovo Community Forums if you have any further queries!
    Did someone help you today? Press the star on the left to thank them with a Kudo’s!
    Cheers!
    Hemanth Kumar
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • Issue with using N'...' values in a where clause against a function index

    We have a table that is defined with non Unicode columns with a UPPER(..) function index on the index column (to allow searching in any alphabetic case)
    e.g.
    create table my_table
    index_column varchar2(20),
    desc_column varchar2(40)
    create index my_table_idx as on my_table(UPPER(index_column));
    there is approx. > 10 million rows in this table
    The issue we have is that when we do the following select
    select index_column, desc_column from my_table
    where upper(index_column) = 'SOME VALUE'; this statement runs in approx 0.03 seconds which is great
    But we also have some statements that run as
    select index_column, desc_column from my_table
    where upper(index_column) = N'SOME VALUE'; notice the N'...' string (unicode) value used. This ends up doing a full table scan (> 5 seconds)
    So... the question is how can i make this select statement passing in a Unicode string value hit this function based UPPER index? Is there anyway?
    I have tried these extra indexes - to no avail
    create index my_table_idx as on my_table(UPPER(CAST(index_column as nvarchar2(20)));
    and
    create index my_table_idx as on my_table(UPPER(COMPOSE(index_column)));
    I assumed Oracle should have done and implicit conversion back to a non unicode string value and then passed that value into the UPPER(...) function index, but it appears as though Oracle isn't recognizing that the column is a different type (varchar2 vs nvarchar2)
    Any help greatly appreciated?

    Horrible amount of irrelevant tags, and the only thing relevant , the four digit version, is of course not mentioned.
    Also the characterset of the database is relevant.
    As far as I know in 11g and higher one no longer needs the N'<string construct>'
    As to implicit conversion
    assume <number_column> = '9'
    Oracle always converts this into
    to_char(<number_column>='9'
    Same applies to your case.
    Try leaving out the N, check whether it works and whether your function based index is used.
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • Best-practice for use of object styles to manage image text wrap issues when aiming at both print and EPUB output?

    I have a work-flow question about object styles, text-wrap, and preparing a long document with lots of images for dual print/EPUB output in InDesign CC 2014. I am sort of experienced with InDesign but new to EPUB export. I have hundreds of pages and

  • N95 8Gb - no longer able to pair with Jabra BT8040

    Hi, Last week I was prompted to upgrade the software on my N95 8Gb after being prompted. So I backup the phone (everthing ticked) and then upgraded to software v30.0.018, 23-07-08, RM-320, Nokia N95 (94.01). The upgrade when ahead without any issues,

  • LRT214 DNS Proxy stops working

    Hi, I have been using the LRT214 for a few months now. I have a few hostnames in the 'Internal DNS list' for internal devices. So I set DHCP to use 'DNS Proxy' and then set the LRT214 to use google dns. It works well most of the time - clients can re

  • Can't Download After Effects?

    So I wanted to download After Effects trial version. Whenever I click on the trial button, I get redirected to the Creative Cloud App. But a download doesn't start - actually, nothing happens. So I'm scrolling down in APPS in Creative Cloud but I can

  • Apple TV connected to TV and I have blank Screen...

    My TV can accesp 720p pictures, howeve, I have a blank screen! TV is a Sony Bravia KDL-32BX300. HELP!!!