Query for a value result when no rows found

Kindly help me out when I use following query it return no record but I want 0 against this query how plz let me know
select b.accode,decode(sum(b.debit),null,0,sum(b.debit)) op_dr,
decode(sum(b.credit),null,0,sum(b.credit)) op_cr,
c.actitle
from v_mast a, v_det b, chart c
where a.v_type=b.v_type
and a.vouchno=b.vouchno
and b.accode=c.accode
and a.VOID='F'
and a.posted_by is not null
and a.v_date between '01-JAN-06' and '31-JAN-06'
and b.accode in (select accode from account where open='T')
and b.accode in (select accode from chart)
and a.v_type in ('RN','PV','CV','RV','JV')
and b.accode = '3050571'
group by b.accode,c.actitle
order by b.accode
Result is : No rows found but is there any possibilities that it will give me following result
Accode op_dr op_cr
3050571 0 0

Why not respond to the earlier threads ?
Query
and
0 when no records found
Regards,
Rob.
Message was edited by:
Rob van Wijk
PS: Of course you could do a
<your query> union all select 3050571,0,0,null from dual
It answers the question, but I doubt that this is what you want.

Similar Messages

  • Execute a query for each value returned by subquery

    Hy, I have a query and a subquery(both of them are selects) and I want the outer query to be executed for each value returned by the subquery but the outer query has to return only one result.
    For example, the following query is right for what I want?:
    the following query finds out which authors live in the same city by looking at the postal code:
    select au_fname, au_lname, city
    from authors
    where city = all
    (select city
    from authors
    where postalcode like "946%")
    I undertand the sentence "select au_fname, au_lname, city from authors where city=" will be executed for each value returned by "select city from authors where postalcode like "946%"". Is this right?
    Thanks

    Hi,
    user13162080 wrote:
    Hy, I have a query and a subquery(both of them are selects) and I want the outer query to be executed for each value returned by the subquery but the outer query has to return only one result. Sorry, I don't understand what you want. What if several rows in the table meet all the criteria? Do you only want some kind of summary of all of them?
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
    For example, the following query is right for what I want?:
    the following query finds out which authors live in the same city by looking at the postal code:
    select au_fname, au_lname, city
    from authors
    where city = all
    (select city
    from authors
    where postalcode like "946%")As I said earlier, I don't know what you want , but whatever it is, the query above is probably not the right way to get it.
    Perhaps you meant "IN" instead of "= ALL", like this:
    SELECT  au_fname, au_lname, city
    FROM      authors
    WHERE      city     IN          -- ***NOT***  = all
              (   SELECT  city
                  FROM    authors
                  WHERE   postalcode LIKE "946%"
    I undertand the sentence "select au_fname, au_lname, city from authors where city=" will be executed for each value returned by "select city from authors where postalcode like "946%"". Is this right?No; the main query will be executed once, and the sub-query will be executed once. The rows in the main query will be compared to the results of the sub-query, to see if they will be included in the result set or not. This goes both for the original query you posted, and the modified version I posted.
    InoL wrote:
    Maybe I don't understand exactly what you want, or you gave a bad example. But your example is simply:
    select au_fname, au_lname, city
    from authors
    where postalcode like '946%'
    No; consider this data:
    INSERT INTO authors (au_lname, city, postalcode) VALUES ('Virgil',     'Oakland',     '94601');
    INSERT INTO authors (au_lname, city, postalcode) VALUES ('Steinbeck',     'Oakland',     NULL);
    INSERT INTO authors (au_lname, city, postalcode) VALUES ('Grass',     'Emeryville',     '94608');What OP posted would return no rows, because nobody is in both 'Oakland' and 'Emeryville'.
    What you posted would return 'Virgil' and 'Grass'.
    What I posted would reutn all 3 rows, including Steinbeck, whose city is known to be related to a '946%' postalcode, even though his own postalcode is missing.
    Edited by: Frank Kulash on Feb 9, 2011 1:06 PM

  • Query not showing detailed result when run through query Designer or Portal

    Hi,
    There is one query which not showing detailed result while running through Query Designer or run in Portal.
    But strange thing is that it is showing the detailed result when i run it through BeX Analyzer.
    While all the other queries don't have this problem in system. All showing the correct detailed result.
    If anyone have some idea on this issue plz let me know.
    Regards,
    Javed
    Edited by: Javed Akhtar on Jul 7, 2009 3:59 PM

    Hi,
    We can do this setting in WAD. Please check the web template and try to remove that setting. When you have hierarchy then we can display only till certain level in portal, this setting is done in web template APIs, but in bex analyzer you can see all the detailed information.
    Edited
    Go through this thread for some more detailed information
    http://help.sap.com/saphelp_nw2004s/helpdata/en/44/7b5f0a95ce12d0e10000000a422035/frameset.htm
    Regards,
    rik

  • Query for Price difference account when item is not sold but not on stock

    Hi Experts!
    One of my clients accountant requires a report which will help for what to do with the balance of the price difference account.
    At the and of the year there are some postings on this account, but not every item that hadnt been on stock when A/P Invoice arrived were sold. Some item were waistrel and put into a waistrel warehouse, but not sold.Some item were sent back to the supplier, but not sold.
    Is it possibble to make a query for knowing where to post the balance of the price difference account? Not all should be post to the Cost of goods sold.
    Thank you in advance!

    Hi,
    The query is possible.  However, it is a complicated one. It is also need to involve detailed analysis to your transaction histories.  You may start from OINM table to check.
    Thanks,
    Gordon

  • Field values erases when Add Row button is pressed in Master Detail Form

    Hi,
    I am using APEX 4.0. There is a master-detail form in a page, this has 5 rows in it by default, has a Add row and a Delete button. I face two problems now:
    1. When the values are entered in all the 5 rows, that are in default, and Add Row button is clicked, these values are entered in the DB, but they are erased from the interface. Means when user clicks Add row he don't see the old values he has entered. All new empty rows are only seen. This might confuse the user. How can I resolve this.
    2. The values are saved to the DB only when the Add row button is clicked, so suppose if the user enters some wrong values in the default rows and after he clicks Delete button, all the field values are erased. Is there a way to delete only that particular row? (Please note: the values are not saved to the DB, unless the Add Row button is clicked)
    Please let me know how to resolve these 2 issues.
    Thanks.

    So let me get this straight:
    You enter information into a tabular form and then click the add row and the data is being duplicated from the prior row or being inserted into the table ?
    Thank you,
    Tony Miller
    Webster, TX
    A lady came up to me on the street, pointed at my suede jacket and said "Do you know a cow was murdered to make that jacket?"
    "I didn't know there were any witnesses", I replied " Now I'll have to kill you too"

  • Query for a Value Set

    Is there any way to get one record for each of orgs? I would like to use this query in a value set but I can put the word distinct in a value set SQL statement. Any Ideas?
    SELECT
    haou.NAME ORGANIZATION_NAME
    FROM
    hr.per_all_assignments_f paaf,
    hr_all_organization_units haou
    WHERE haou.Organization_id = paaf.Organization_id
    AND paaf.primary_flag = 'Y'
    AND paaf.assignment_type = 'E'
    AND sysdate BETWEEN paaf.effective_start_date AND paaf.effective_end_date
    order by 1

    Found it...
    select name from hr_all_organization_units b
    where organization_id in (select organization_id from per_all_assignments_f a
    where a.organization_id = b.organization_id )
    order by 1

  • For exception on result ; Highlight the rows

    Hi guys
    could be a simple question with a "not so simple" answer - Is there a way in Bex to read the result row and compare with a condition say - for result < 100 ; Highlight the individual rows that add up to give the result row ?
    if it can be done , Please tell me how ?
    appreciate your inputs,
    thanks
    Shweta

    Hello,
    If a query, on BEx Analyzer, I think this is not possible.
    However, if you save the query as workbook, you can add insert any macro code on SAPBEXONREFRESH
    Then, when you refresh your workbook, the macro will be executed and you can create a code to compare the rows values.
    You can access the SAPBEXONREFRESH procedure pressing ALT + F11.
    Thanks
    Edward John

  • Query for item warehouses stock in a row

    hi all,
    How to retreive item warehouse stock in a row using query ?
    SELECT T0.ItemCode, T1.ItemName, T2.ItmsGrpNam,
    (Select WhsCode from OITW Where
    WhsCode=T0.WhsCode and ItemCode=T0.ItemCode) as 'Wh',
    (Select OnHand From OITW Where
    Whscode = T0.WhsCode and Itemcode=T0.ItemCode) as 'Whstck'
    FROM OITW T0  INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T1.ItmsGrpCod = T2.ItmsGrpCod
    WHERE T0.ItemCode NOT IN 'a-item'AND
    T2.ItmsGrpNam LIKE '%%test%%'
    and T0.Onhand > 0
    ORDER BY T0.ItemCode
    Anyone correct query so that it will retrieve item warehouse stock in a single row.
    Thanks
    Jeyakanthan

    I have tested your query, the result is just like you wish. The code can be simplified to:
    SELECT T0.ItemCode, T1.ItemName, T2.ItmsGrpNam, T0.WhsCode as 'Wh',T0.OnHand as 'Whstck'
    FROM DBO.OITW T0 
    INNER JOIN DBO.OITM T1 ON T0.ItemCode = T1.ItemCode
    INNER JOIN DBO.OITB T2 ON T1.ItmsGrpCod = T2.ItmsGrpCod
    WHERE T0.ItemCode NOT IN ('a-item') AND T2.ItmsGrpNam LIKE '%[%test%]%'
    and T0.Onhand > 0
    ORDER BY T0.ItemCode, T0.WhsCode
    If you want each item has only one row and warehouse on hand column-wised, you have to use as much as SELECT for each column in according to your number of warehouses. It would be look like this one:
    SELECT T0.ItemCode, T0.ItemName, T1.ItmsGrpNam,
    (SELECT OnHand FROM OITW WHERE ItemCode = T0.ItemCode AND WhsCode Like 'Whs1') AS 'Whs1 On Hand' ,
    (SELECT OnHand FROM OITW WHERE ItemCode = T0.ItemCode AND WhsCode Like 'Whs2') AS 'Whs2 On Hand' ,
    (SELECT OnHand FROM OITW WHERE ItemCode = T0.ItemCode AND WhsCode Like 'Whs3') AS 'Whs3 On Hand'
    FROM DBO.OITM T0 
    INNER JOIN DBO.OITB T1 ON T1.ItmsGrpCod = T0.ItmsGrpCod
    WHERE T0.ItemCode NOT IN ('a-item') AND T1.ItmsGrpNam LIKE '%[%test%]%'
    and T0.Onhand > 0
    ORDER BY T0.ItemCode
    Thanks,
    Gordon

  • SQL query for updating values in same cell of a table

    Hi All,
    I'm stuck with a problem and it stands as follows:
    Table name: Track
    Part1  Part2  Part3
    NULL   NULL   NULL
    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,); it should not be overwritten, neither they should appear in separate row, in fact they should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    The new values of Part1 should appear in next row only when value of Part3 changes, so if Part3 changes from SUBM1 to SUBM2, it should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    1,2,3    5          SUBM2
    Count of values in Part1 never exceeds the value of Part2, so if Part2 is 5, then Part1 will look like 1,2,3,4,5. So in other words loop will run only up to the value of Part2.
    Please advise how this could be achieved?
    Kind regards,
    Aniruddha Jagdale

    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
    No, don't go there.
    This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
    to write complex and higly inefficient code.
    The values in Part1 should be in a separate table, with one value per row.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query to calculate value and produce new rows

    QUARTER CUSTOMER PRODUCT RETAIL_SALES_AMT     WHOLESALE_AMT
    01/01/2006     ABC VACCUM CLEANER 454234.00 65633456.00
    04/01/2006     ABC VACCUM CLEANER 324562.00 45333234.00
    07/01/2006     ABC VACCUM CLEANER NULL 67845423.00
    10/01/2006     ABC VACCUM CLEANER NULL 67453453.00
    01/01/2007     ABC VACCUM CLEANER NULL 56754633.00
    04/01/2007     ABC VACCUM CLEANER NULL 45423434.00
    Hi guys,
    It is a situation where i have to produce some new rows with projected RETAIL_SALES_AMT based on the last quarter's
    RETAIL_SALES_AMOUNT and next quarte'rs WHOLESALE_AMT. As you can see from the sample data for a specific customer,
    product i have retail_sales_amt populated only upto 04/01/2006 but WHOLE_SALE amt for the same product and customer
    are there upto 04/01/2007.
    I have to produce a PROJECTED RETAIL_SALES_AMT and it should be inserted as a new row with a flag to identify
    a projected row. Here in this case i have to produce a new row for 07/01/2006,10/01/2006 & 01/01/2007 projecting
    the RETAIL_SALES_AMT. The formulae for calculation is as under:
    projected retail_sales_amt for 07/01/2006=.345+( (07/01/2006 whole_sales - 04/01/2006 whole_sales)/(04/01/2006 whole_sale)))
    *04/01/2006 RETAIL_SALES_AMT and going forward for subsequent quarters.
    Is there any way i can use a query to produce these new rows by calculating the RETAIL_SALES_AMT on the fly or any
    procedural way to do it.
    Please help as it looks a bit complicated logic.
    Regards
    Edited by: user626688 on Oct 27, 2009 11:26 AM
    Edited by: user626688 on Oct 27, 2009 11:26 AM
    Edited by: user626688 on Oct 27, 2009 11:27 AM
    Edited by: user626688 on Oct 27, 2009 11:28 AM
    Edited by: user626688 on Oct 27, 2009 11:31 AM
    Edited by: user626688 on Oct 27, 2009 11:32 AM

    I'm not sure if this is exactly what you want but this shows you the possibilities:
    WITH sales_table AS
            SELECT TO_DATE('01/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, 454234 AS RETAIL_SALES_AMT, 65633456 AS WHOLESALE_AMT FROM DUAL UNION ALL
            SELECT TO_DATE('04/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, 324562 AS RETAIL_SALES_AMT, 45333234 AS WHOLESALE_AMT FROM DUAL UNION ALL
            SELECT TO_DATE('07/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 67845423 AS WHOLESALE_AMT FROM DUAL UNION ALL
            SELECT TO_DATE('10/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 67453453 AS WHOLESALE_AMT FROM DUAL UNION ALL
            SELECT TO_DATE('01/01/2007','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 56754633 AS WHOLESALE_AMT FROM DUAL UNION ALL
            SELECT TO_DATE('04/01/2007','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 45423434 AS WHOLESALE_AMT FROM DUAL
    SELECT  QUARTER
    ,       CUSTOMER
    ,       PRODUCT
    ,       RETAIL_SALES_AMT
    ,       WHOLESALE_AMT
    ,       PROJECTED_FLG
    FROM    SALES_TABLE
    MODEL
            DIMENSION BY
                    QUARTER
            ,       CUSTOMER
            ,       PRODUCT
            MEASURES
                    RETAIL_SALES_AMT
            ,       WHOLESALE_AMT
            ,        'F' AS PROJECTED_FLG
            RULES
                    PROJECTED_FLG[ANY,ANY,ANY] =  (CASE
                                                                            WHEN RETAIL_SALES_AMT[cv(),cv(),cv()] IS NULL AND RETAIL_SALES_AMT[cv(),cv(),cv()] IS PRESENT
                                                                            THEN 'T'
                                                                            ELSE 'F'
                                     END)
             ,     RETAIL_SALES_AMT[ANY,ANY,ANY] = (CASE
                                                            WHEN RETAIL_SALES_AMT[cv(),cv(),cv()] IS NULL AND RETAIL_SALES_AMT[cv(),cv(),cv()] IS PRESENT
                                                            THEN RETAIL_SALES_AMT[ADD_MONTHS(cv(),-3),cv(),cv()]*(.345 + ((WHOLESALE_AMT[cv(),cv(),cv()] - WHOLESALE_AMT[ADD_MONTHS(cv(),-3),cv(),cv()])/WHOLESALE_AMT[ADD_MONTHS(cv(),-3),cv(),cv()]))
                                                    ELSE
                                                    RETAIL_SALES_AMT[cv(),cv(),cv()]
                                                    END)     
    ORDER BY 1, 2, 3Results:
    QUARTER             CUS PRODUCT        RETAIL_SALES_AMT WHOLESALE_AMT P
    01/01/2006 00:00:00 ABC VACUUM CLEANER           454234      65633456 F
    04/01/2006 00:00:00 ABC VACUUM CLEANER           324562      45333234 F
    07/01/2006 00:00:00 ABC VACUUM CLEANER       273149.267      67845423 T
    10/01/2006 00:00:00 ABC VACUUM CLEANER       92658.4052      67453453 T
    01/01/2007 00:00:00 ABC VACUUM CLEANER       17270.5619      56754633 T
    04/01/2007 00:00:00 ABC VACUUM CLEANER       2510.23463      45423434 TEdited by: Centinul on Oct 27, 2009 3:00 PM

  • SQL Query for take values on excle sheet

     i have the query `select EmpId,AttenDate,status from dbo.Attendance`
    it will give me this
    1500011 2014-09-01 00:00:00.000
    A
    1500011 2014-09-02 00:00:00.000
    A
    1500011 2014-09-03 00:00:00.000
    A
    1500011 2014-09-04 00:00:00.000
    A
    1500011 2014-09-05 00:00:00.000
    A
    1500011 2014-09-06 00:00:00.000
    P
    1500011 2014-09-07 00:00:00.000
    A
    upto   2014-09-31  00:00:00.000
    A
    68 2014-08-01 00:00:00.000
    A
    68 2014-08-02 00:00:00.000
    P
    68 2014-08-03 00:00:00.000
    A
    68  2014-09-07 00:00:00.000 A
    upto   2014-09-31  00:00:00.000
    A
    Now i want to print it into the excel sheet 
    with is format
    Empid 1
    2 3
    4 5
    6 7
    8 upto 31
    1500011 A   A A
    A A
    P A 
    A upto A
    68     A
    A P
    ....................upto A
    Please suggest me??

     
    Hi SachinDholess,
    Based on my understanding, you want to merge the attendance records for each EmpID into one row as below snapshot rather than in rows, right?
    According to your description, I created and populate the attendance records of September for EmpID
    1500011 and records of August and September for EmpID 68
    to simulate your scenario. In this scenario, the Stored Procedure
    procGetEmpAtt would help you to get the data like above snapshot during a given period. Please see the below code.
    USE TestDB;
    IF OBJECT_ID('dbo.Attendance') IS NOT NULL
    DROP TABLE dbo.Attendance;
    GO
    CREATE TABLE Attendance
    EmpID INT,
    AttenDate DATETIME,
    [status] VARCHAR(99)
    GO
    --Create and Populate the Nums Auxiliary Table
    SET NOCOUNT ON;
    SET ROWCOUNT 0;
    IF OBJECT_ID('dbo.Nums', 'U') IS NOT NULL
    DROP TABLE dbo.Nums;
    CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY);
    DECLARE @max AS INT, @rc AS INT;
    SET @max = 1000;
    SET @rc = 1;
    INSERT INTO dbo.Nums(n) VALUES(1);
    WHILE @rc * 2 <= @max
    BEGIN
    INSERT INTO dbo.Nums(n) SELECT n + @rc FROM dbo.Nums;
    SET @rc = @rc * 2;
    END
    INSERT INTO dbo.Nums(n)
    SELECT n + @rc FROM dbo.Nums WHERE n + @rc <= @max;
    GO
    --Insert records of September for EmpID 1500011
    INSERT INTO Attendance VALUES(1500011,'2014-09-01 00:00:00.000', 'A');
    INSERT INTO Attendance
    SELECT EmpID, DATEADD(DAY,n,AttenDate), [status] FROM Attendance join nums ON nums.n<30
    WHERE EMPID=1500011;
    --Insert records of September and August for EmpID 68
    INSERT INTO Attendance VALUES(68,'2014-08-01 00:00:00.000', 'A');
    INSERT INTO Attendance
    SELECT EmpID, DATEADD(DAY,n,AttenDate), [status] FROM Attendance join nums ON nums.n<61
    WHERE EMPID=68;
    DROP TABLE dbo.Nums;
    IF (OBJECT_ID('procGetEmpAtt', 'P') IS NOT NULL)
    DROP PROC procGetEmpAtt
    GO
    CREATE PROC procGetEmpAtt(@startDT DATETIME, @endDT DATETIME)
    AS
    DECLARE @DynamicPivotQuery AS NVARCHAR(MAX);
    DECLARE @ColumnName AS NVARCHAR(MAX);
    DECLARE @Columns AS NVARCHAR(MAX);
    --Get distinct values of the PIVOT Column
    SELECT @ColumnName= ISNULL(@ColumnName + ',','')+ 'ISNULL('+QUOTENAME(dt)+',''Not Recored'') AS '+QUOTENAME(dt),
    @Columns=ISNULL(@Columns + ',','')+QUOTENAME(dt)
    FROM (SELECT DISTINCT CONVERT(varchar(12) , AttenDate, 112 ) as dt FROM Attendance WHERE AttenDate BETWEEN @startDT AND @endDT ) AS A ;
    --Prepare the dynamic PIVOT query
    SET @DynamicPivotQuery =
    N'SELECT EmpID, ' + @ColumnName + '
    FROM Attendance
    PIVOT(MAX([status])
    FOR AttenDate IN (' + @Columns + ')) AS PVTTable ORDER BY EmpID DESC' ;
    --Execute the dynamic Pivot Query
    EXEC sp_executesql @DynamicPivotQuery ;
    GO
    Test example
    SET NOCOUNT ON;
    SET ROWCOUNT 0;
    EXEC procGetEmpAtt
    @startDT='2014-08-29',
    @endDT='2014-09-15'
    The key in this  Stored Procedure is the dynamic Pivot statement, click
    here for more details.
    By the way, I didn’t quite get your point until I copied your description into a Word document. Kindly mind the format of the description you post, a better  formatted one would lead to a much quicker response.
    If you have any question, feel free to let me know.
    Best Regards,
    Eric Zhang

  • Query for multiple value search

    Hi
    I got struck when I try to construct SQL query to fetch multiple values in WHERE clause.
    SELECT columnName from someTable
    WHERE someValue = {here is the problem, I have multiple values here which I get from some array}
    Is there any way I can put multiple values to where clause?

    here we go
    this????
    SQL> var LIST varchar2(200)
    SQL> EXEC :LIST := '10,20';
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL>  SELECT items.EXTRACT('/l/text()').getStringVal() item
      2   FROM TABLE(XMLSEQUENCE(
      3   EXTRACT(XMLTYPE('<all><l>'||
      4   REPLACE(:LIST,',','</l><l>')||'</l></all>')
      5  ,'/all/l'))) items;
    ITEM
    10
    20
    Elapsed: 00:00:00.04
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT empno,
      2         ename
      3    FROM emp
      4   WHERE dno IN (SELECT items.EXTRACT ('/l/text()').getStringVal () item
      5                   FROM TABLE (XMLSEQUENCE (EXTRACT
      6*                   (XMLTYPE ('<all><l>' || REPLACE (:LIST, ',', '</l><l>') || '</l></all>'), '/all/l') ) )
    SQL> /
         EMPNO ENAME
          7934 MILLER
          7839 KING
          7782 CLARK
          7902 FORD
          7876 ADAMS
          7788 SCOTT
          7566 JONES
          7369 SMITH
    8 rows selected.

  • SQL query for zero or more than 1 row

    have 2 tables Table1 and Table2
    Table1 contains one varchar2 column Col1 with values: id1, id2, id3, id4, .....id9
    Table2 contains two varchar2 columns with values:
    Col1     Col2
    id1     some1
    id1     some2
    id3     some3
    id4     some4
    id9     some5
    id9     some6
    Table1 and Table2 join on Table1.col1 = Table2.col1
    I want to find those rows in Table1 that have zero or more than one values in Table2
    So the output in the above case would be
    id1 (since it has more than one corresponding values in Table2)
    id2 (since it does not have corresponding value in Table2)
    id9 (since it has more than one corresponding values in Table2)

    One way:
    select table1.col1
    from table1 left outer join table2 on table1.col1 = table2.col1
    group by table1.col1 having count(table2.col1) != 1
    Where there is no match, table2.col1 in the outer join will be null, so the count will be zero.
    Where there are multiple matches the count will be > 1.
    Untested because you didn't supply table and data creation scripts. See Re: 2. How do I ask a question on the forums?

  • SQL Query for max values!!

    Hi to all,
    I have four tables
    Tbl_one
    Tbl_two
    Tbl_three
    Tbl_four
    the relation between these tables is
    Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    I want a query like this
    Select tbl_one.com_name, tbl_three.test_date,tbl_four.order_date
    from Tbl_one,Tbl_two,Tbl_three,Tbl_four
    where Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    and tbl_three.test_date in (select max(test_date) from tbl_three)
    and tbl_four.order_date in select(max(order_date from tbl_for)
    and max(test_date)> Max(order_date)
    any way it is possible?
    the real problem is there are multiple test_dates and
    multiple order_date for same seq in tbl_one.seq.
    eg: -
    name (indian) which has three or more test_date and each test_date have more than one order_date
    indian (name) 01/01/2009(test_date) has ---- 01/10/2009, 01/20/2009 and 01/21/2009) order_dates
    india(name) 02/02/2009 (test_date) has ----- 02/10/2009, 02/20/2009 and 02/30/2009 (order_dates)
    india(name) 03/03/2009 test_date has ----- 03/10/2009, 03/20/2009 , 03/25/2009 (order_dates).
    japan has the same situation and so on
    what i wanted from the query is
    max(test_date)= 03/03/2009 > max(order_date)=03/25/2009
    ans: -
    name
    india(name) 03/03/2009 (test_date) 03/25/2009(order_date)
    etc. etc . etc.
    thanks!!
    Edited by: pl/sql baby on Mar 24, 2009 10:45 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:47 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:51 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:57 AM

    Please use tags either side of code / data (to preserve the formatting and spacing).
    I don't understand your requirement... 03/03/2009 is not greater than 03/25/2009 ?
    Could you please be clearer in your input/output samples and explain more about how to generate the output?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query for selecting current date when running report

    Hi all
    I need a query that will copy today's date on posted sales order via DTW then that query will be linked to an alert and be sent to the sales manager every morning after the import went through successfully.
    The report at the moment is running fine as i pulling through the other info required the only problem is it's pulling all the sales orrders on the system , we want it to pull only the days orders imported.

    You could use either of these queries
    SELECT T0.DocNum, T0.DocDueDate, T0.CardCode, T0.CardName, T0.DocTotal, T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK
    FROM [dbo\].[ORDR\] T0
    WHERE T0.DocDate = GETDATE()
    ORDER BY T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK, T0.DocDueDate
    OR
    SELECT T0.DocNum, T0.DocDueDate, T0.CardCode, T0.CardName, T0.DocTotal, T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK
    FROM [dbo\].[ORDR\] T0
    WHERE DATEDIFF(Day, T0.DocDate, GETDATE()) = 0
    ORDER BY T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK, T0.DocDueDate

Maybe you are looking for

  • Problem with date formatting after having downloaded client Oracle 10.2.0.3

    Hallo Could it be for the reason above, in order to have sqlplus on my application server, that some dates are displayed on several occurences (not every, i. e. only in read-only-fields) on my application, with the unwished format YY/MMM/DD instead o

  • Videos freeze + IE stops responding after 5 mins

    I have been having trouble with Youtube videos. Every single video will freeze after 5 minutes. However, the audio will continue playing until the entire browser stops responding. The video eventually resumes after the browser recovers. I have tried

  • Changing Mailserver Name Issues?

    I have an older server doing both email and web and I plan to split the services across a couple of boxes and limit this box to just doing email. So far it has used the same domain name like foo.bar.com for both the address of the email and webserver

  • Help with conditional answer, cont'd "blank" discussion

    Got the answer to my blank question below, but the client has asked that when an item is overshipped, there should be a "0" in the backordered spot. When the amount shipped is the same as the amount ordered, it should be "blank". When the item ordere

  • Rollback to the older format?

    I am not happy with the new look and feel of the Apple support discussions group. It is very app-y like and its not friendly to older PCs/Macs or a slow Internet connection, like an inferior Verizon Mobile Broadband, where recently I am only getting