SQL Query - Report on multiple table

Hi Experts
Firstly, I am an amateur at generating SQL Queries!
I am trying to create a Report of All Invoices/Credit Notes generated in a date range combined with all open Sales Orders.
This is my attempt - I am getting all Sales Orders but only want to have Open Sales Orders.
SELECT T0.[DocNum], T0.[DocType], T0.[cardcode] AS 'Cust. ID', T0.[cardName] AS 'Customer', T0.[TransId], T0.[TaxDate] AS 'Date', T1.[SlpName] AS 'AC Mgr', (T0.[DocTotal] -T0.[VatSum]) AS'NETT', T0.[DocStatus],T0.[U_BusCategory] AS 'Business Cat.', T0.[U_TERM] AS 'TERM', T2.OpprId, T2.Name
FROM [dbo].[OINV]  T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode 
LEFT OUTER JOIN OOPR T2 ON T0.U_RTNo = T2.DocNum
WHERE CONVERT(nchar(8), T0.DocDate, 112) >= '[%0]'  AND CONVERT(nchar(8), T0.DocDate, 112) <= '[%1]'
UNION
SELECT T0.[DocNum], T0.[DocType], T0.[cardcode], T0.[cardName], T0.[TransId], T0.[TaxDate] AS 'Date', T1.[SlpName] AS 'AC Mgr', -(T0.[DocTotal] -T0.[VatSum]) AS'NETT', T0.[DocStatus],T0.[U_BusCategory],T0.[U_TERM] AS 'TERM', T2.OpprId AS 'Oppr. ID.', T2.Name AS 'Oppr. Name'
FROM [dbo].[ORIN]  T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
LEFT OUTER JOIN OOPR T2 ON T0.U_RTNo = T2.DocNum
WHERE CONVERT(nchar(8), T0.DocDate, 112) >= '[%0]'  AND CONVERT(nchar(8), T0.DocDate, 112) <= '[%1]'
UNION
SELECT T0.[DocNum], T0.[DocType], T0.[CardCode], T0.[CardName], T0.[TransId], T0.[TaxDate], T1.[SlpName], (T0.[DocTotal]-T0.[VatSum]), T0.[DocStatus], T0.[U_BusCategory], T0.[U_TERM], T2.OpprId AS 'Oppr. ID.', T2.Name AS 'Oppr. Name'
FROM ORDR T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
LEFT OUTER JOIN OOPR T2 ON T0.U_RTNo = T2.DocNum
WHERE CONVERT(nchar(8), T0.DocDate, 112) >= '[%0]'  AND CONVERT(nchar(8), T0.DocDate, 112) <= '[%1]' 
Any help would be much appreciated
Derek

Dear Mr Vard,
The field in the ORDR table that will tell you if the document is closed or open is the DocStatus.
C = Closed and O = Open
You could add another where clause:
where t0.DocStatus = 'c'
to the last query you added (the one referring to the ORDR table).
Please, let me know if this helps you.
Marcella Rivi
SAP Business One Forums Team

Similar Messages

  • SQL Query Report from DB2 Tables

    Team,
    Our HTML DB application requires us to build a Report against a DB2 table. In addition, we are required to view the detail of the selected DB2 data on a second page, much like the 2 page report as generated by the wizard.
    So...what is the best way to present DB2 data in both Report and Detail format using HTML DB? Better yet...how can DB2 tables be set up/connected/defined to HTML DB so they operate just like the Oracle tables which reside inside the Oracle database?
    Thanks for your help.
    Howard

    An addendum to my original post....
    How about the use of a JDBC driver? Is there one available to meet my requirements?
    Thanks again
    Howard

  • Setting a Default Value in SQL Query Report

    Hello:
    We are using a SQL Query Report to provide a mass update to a table. We are using the apex.collection and having it display a number of records in a SQL Query Report for mass update. We have 14 columns in the report, for which the first 11 are populated via the collection. The remaining 3 are open for input but the individual making the updates. We've were able to provide a default value for 2 of the remaining 3 columns using a named LOV's - however the fourth column we would like to default a sysdate - but we are not successful.
    We've attempted many things but none seem to work, including adding that column to the collection and assigning it a default sysdate value. We've also tried changing the settings in the report attributes --> Tabular Form Elements by setting the Display as to: Datepicker, Default type to PL/SQL Expression and setting the default to sysdate. We've also tried caputuring a date on the previous page and loading it onto the report page and trying to default the date column to a page item default.
    I'd appreciate any help.
    Thanks
    FYI - we are using version 3.2

    use as default
    to_char(sysdate, 'dd/mm/yyy') where the format is your application or item date format

  • How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?

    1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
    When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed  in the stat plan  ?
    2. Does rowsource statistics gives some kind of  understanding of Extended stats ?

    You can get Row Source Statistics only *after* the SQL has been executed.  An Explain Plan midway cannot give you row source statistics.
    To get row source statistics either set STATISTICS_LEVEL='ALL'  in the session that executes theSQL OR use the Hint "gather_plan_statistics"  in the SQL being executed.
    Then use dbms_xplan.display_cursor
    Hemant K Chitale

  • How do you select a clob column in an SQL query report?

    I must be missing something fundamental as there is practically no help on this on the forum.
    All I want to do is ...
    select numcol,aclob_col from table
    in an SQL Query report.
    Sounds easy??? I get no data appearing in the clob column. Doesn't work in SQL Workshop either. What's the catch??
    regards
    Paul P

    Paul,
    It works when I try it. What version of Application Express, what is the table DDL, the exact query, and how much data is in the clob columns?
    Scott

  • SQL Query Report (Customize link)

    I have an SQL query report with bind variables so that users can choose conditions for the query. If I don't have any conditions, the report is empty. How do I get it to display all the records. I tried typing * but it didn't work.
    Basically I want it to act like the Query Wizard's Customize feature. The report give me all the records. I can query one field or all the fields.
    In the SQL report's Customize feature, I have to enter a value for all the bind variables I have. What if I just want to query one field. What do I put in the others to indicate that I want all. I hope this makes some sort of sense and that someone out there knows what I'm blabbing about.

    Hi,
    I h've same type of requirement in most of my reports in the application and I h've solved this in the sql of the report itself. Let's see a example report from the table scott.emp with a sql like
    Select EMPNO,
    ENAME,
    JOB,
    MGR,
    HIREDATE,
    SAL,
    DEPTNO
    From scott.emp
    Where EMPNO = nvl(:v_empno,EMPNO)
    and DEPTNO = nvl(:v_deptno,DEPTNO)
    where :v_empno and :v_deptno are bind variables to this report and if there is no arguements passed to these arguements all the records will be retrieved from the table ..likeley if value for any one of these arguements is passed then this sql will return only those records which meet that condition.
    Hope this helps
    -Krishnamurthy

  • SQL Query report region that only queries on first load

    Hello all,
    Is there any way in which you can prevent a SQL Query report region from quering data after every refresh?
    I would like to make a report that queries on the first load, but then I would like to change the individual values, and reload to show the change, but every time I reload the page the columns are queried and the original values are displayed once again...
    any ideas?
    -Mux

    Chet,
    I created a header process to create the HTMLDB_COLLECTION. It is something like:
    HTMLDB_COLLECTION.CREATE_COLLECTION_FROM_QUERY(
    p_collection_name => 'Course_Data',
    p_query => 'SELECT DISTINCT COURSE_ID, HTMLDB_ITEM.CHECKBOX(14,COURSE_ID) as "checker", TITLE, SUBJECT, COURSE_NUMB, SECTION, ENROLLED, null as "temp_term", null as "temp_title", null as "temp_crse_id", null as "temp_subj", null as "temp_crse_numb", null as "temp_sect", FROM DB_TBL_A, DB_TBL_B, DB_TBL_C, DB_TBL_D, DB_TBL_E, DB_TBL_F WHERE ...');
    The names were changed, for obvious reasons.
    I then created an SQL Report Region to see if it would work. The SQL is:
    SELECT c001, c002, c003
    FROM htmldb_collections
    WHERE collection_name = 'COURSE_DATA'
    When I run the page it says:
    ORA-20104: create_collection_from_query Error:ORA-20104: create_collection_from_query ExecErr:ORA-01008: not all variables bound
    Any idea why this is happening?
    I'm new to HTMLDB_COLLECTIONS, so I may be doing something wrong
    -Mux

  • Give me the sql query which calculte the table size in oracle 10g ecc 6.0

    Hi expert,
    Please  give me the sql query which calculte the table size in oracle 10g ecc 6.0.
    Regards

    Orkun Gedik wrote:
    select segment_name, sum(bytes)/(1024*1024) from dba_segments where segment_name = '<TABLE_NAME>' group by segment_name;
    Hi,
    This delivers possibly wrong data in MCOD installations.
    Depending on Oracle Version and Patchlevel dba_segments does not always have the correct data,
    at any time esp. for indexes right after being rebuild parallel (Even in DB02 because it is using USER_SEGMENTS).
    Takes a day to get the data back in line (never found out, who did the correction at night, could be RSCOLL00 ?).
    Use above statement with "OWNER = " in WHERE for MCOD or connect as schema owner and use USER_SEGMENTS.
    Use with
    segment_name LIKE '<TABLE_NAME>%'
    if you like to see the related indexes as well.
    For partitioned objects, a join from dba_tables / dba_indexes to dba_tab_partitions/dba_ind_partitions to dba_segments
    might be needed, esp. for hash partitioned tables, depending on how they have been created ( partition names SYS_xxxx).
    Volker

  • SQL Query Report Very slow

    Hi I have a sql query report that is taking very long to render.The query on sql developer comes back in less than a second.Any ideas on what could be wrong?

    Hi
    When posting code on the forum, put {noformat}{noformat} (with the curly brackets and the word code in lowercase) above and below your code like this...
    {noformat}{noformat}
    SELECT *
    FROM emp
    {noformat}{noformat}
    It will then appear like this, preserving formatting...SELECT *
    FROM emp
    Next, how many rows are returned in total, it may be that you have SQL Developer set up to fetch only the first x number of rows?
    Why have you put a CHOOSE hint in there?
    Is it a classic report or an interactive report?
    It looks like you're going over a database link, you really need to provide an explain plan (formatted as I have detailed above), a DRIVING_SITE hint may help you but it's impossible to know without seeing the plan...
    Cheers
    Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Apex - SQL query report.

    Hi,
    Apex - 4.0 and Oracle -11g
    I m having a SQL Query report.
    Query
    SELECT htmldb_item.hidden(1,id) id,
      htmldb_item.select_list_from_query_xl(2,name,'SELECT name ,                                                              
    deptid                                                     
    FROM  emp                                                     
    WHERE name like ''E%''') name,
      htmldb_item.select_list_from_query_xl(3,deptname,'SELECT  deptname from dept where deptid =   ???') deptname
    FROM tabel
    My problem, in the report when the Select list for 'name' has been choosen , then it should retrieve the deptname based on the 'name'.
    Is it possible ?

    you want  select list value should affected in SQL report? i mean redirect and set value to SQL report?

  • Fail to create SQL query report because of ORA-00923

    Hi expert,
    I would like to SQL query report using the following query:
    select min(identified_date) first_identified,
    max(actual_COMPLETE) last_closed,
    count(id) total_issues,
    sum(decode(status,'Open',1,0)) open_issues,
    sum(decode(status,'Pending',1,0)) pending_issues,
    sum(decode(status,'Resolved',1,0)) closed_issues,
    sum(decode(status,'Will Not Resolve',1,0)) not_resolve_issues,
    sum(decode(status,
    'Open',decode(priority,null,1,0),
    0)) open_no_prior,
    sum(decode(status,
    'Open',decode(priority,1,1,0),
    0)) open_prior_1,
    sum(decode(status,
    'Open',decode(priority,'2',1,0),
    0)) open_prior_2
    sum(decode(status,
    'Open',decode(priority,3,1,0),
    0)) open_prior_3,
    sum(decode(status,
    'Open',decode(priority,'4',1,0),
    0)) open_prior_4,
    sum(decode(status,
    'Open',decode(priority,5,1,0),
    0)) open_prior_5
    from SOFTPROJ_issues
    where project_id = :P83_PROJECT
    However, I got the following error during the steps of creation:
    1 error has occurred
    Query cannot be parsed, please check the syntax of your query. (ORA-00923: FROM¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿)
    I wonder why if it is getting the error because I could create the report with the following query without problems:
    select min(identified_date) first_identified,
    max(actual_COMPLETE) last_closed,
    count(id) total_issues,
    sum(decode(status,'Open',1,0)) open_issues,
    sum(decode(status,'Pending',1,0)) pending_issues,
    sum(decode(status,'Resolved',1,0)) closed_issues,
    sum(decode(status,'Will Not Resolve',1,0)) not_resolve_issues,
    sum(decode(status,
    'Open',decode(priority,null,1,0),
    0)) open_no_prior,
    sum(decode(status,
    'Open',decode(priority,1,1,0),
    0)) open_prior_1,
    sum(decode(status,
    'Open',decode(priority,3,1,0),
    0)) open_prior_3,
    sum(decode(status,
    'Open',decode(priority,5,1,0),
    0)) open_prior_5
    from SOFTPROJ_issues
    where project_id = :P83_PROJECT
    1 error has occurred
    Query cannot be parsed, please check the syntax of your query. (ORA-00923: FROM¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿)
    The difference is to add the followings only:
    sum(decode(status,
    'Open',decode(priority,'2',1,0),
    0)) open_prior_2
    sum(decode(status,
    'Open',decode(priority,'4',1,0),
    0)) open_prior_4,
    Does anyone have any idea to resolve the issue?
    Thanks in advance,
    Rui

    By putting a comma after open_prior_2:
    sum(decode(status,
    'Open',decode(priority,'2',1,0),
    0)) open_prior_2,Sima

  • App-V Reporting: SQL query for Excel Pivot Table to display App Usage (H/M/S)

    I recently posted this in the Gallery.  If anyone has any modifications or enhancements please feel free to contribute!  One thing that I'd like to be able to add to it is the ability to only display information for applications/packages that are
    still published, so if anyone can figure out a crafty way to do it...  Thanks!
    http://gallery.technet.microsoft.com/App-V-Reporting-SQL-query-6695d3c3

    I recently posted this in the Gallery.  If anyone has any modifications or enhancements please feel free to contribute!  One thing that I'd like to be able to add to it is the ability to only display information for applications/packages that are
    still published, so if anyone can figure out a crafty way to do it...  Thanks!
    http://gallery.technet.microsoft.com/App-V-Reporting-SQL-query-6695d3c3

  • Forming generic sql query   for joining multiple sap tables in ABAp

    Hi,
    I am new to this abap field ,facing an issue onsap-jco project . I have used RFC_READ_TABLE  FM ,Customized this FM but facing an issue how to write generic  open SQl select statement  for joining multiple tables  using RFC_READ_TABLE .Kindly help on this issue.
    Thanks.

    something like this? If your tuples are not single columns, then you'll have to use dynamic sql to achieve the same result.with
    table_1 as
    (select '|Xyz|Abc|Def|' tuple from dual
    table_2 as
    (select '|Data1|Data21|Data31|Data41|Data51|' tuple from dual union all
    select '|Data2|Data22|Data32|Data42|Data52|' tuple from dual union all
    select '|Data3|Data23|Data33|Data43|Data53|' tuple from dual union all
    select '|Data4|Data24|Data34|Data44|Data54|' tuple from dual union all
    select '|Data5|Data25|Data35|Data45|Data55|' tuple from dual
    select case the_row when 1
                        then tuple
                        else '|---|---|' || substr(tuple,instr(tuple,'|',1,3) + 1)
           end tuple
      from (select substr(a.tuple,instr(a.tuple,'|',:one_one),instr(a.tuple,'|',:one_one + 1)) ||
                   substr(a.tuple,instr(a.tuple,'|',1,:one_two) + 1,instr(a.tuple,'|',1,:one_two + 1) - instr(a.tuple,'|',1,:one_two)) ||
                   substr(b.tuple,instr(b.tuple,'|',1,:two_one) + 1,instr(b.tuple,'|',1,:two_one + 1) - instr(b.tuple,'|',1,:two_one)) ||
                   substr(b.tuple,instr(b.tuple,'|',1,:two_two) + 1,instr(b.tuple,'|',1,:two_two + 1) - instr(b.tuple,'|',1,:two_two)) tuple,
                   rownum the_row
              from table_1 a,table_2 b
    order by the_rowRegards
    Etbin
    Message was edited by:Etbin
    user596003

  • Using Package to produce pl/sql function body returning sql query Report

    I have existing code that we want to use in building reports in APEX. We are needing to modify it slightly to handle some new requirements, but would like to use them in reports based upon SQL query (pl/sql function body returning sql query) functionality.
    Any suggestions as how to call these in an APEX report region?
    Thank you,
    Tony Miller
    UTMB/EHN

    Hi Tony-
    I am also v new to Apex and you may have answered a question I was in search of. I, however, now have a couple more. First a bit of background-- Like in your situation, my college has a lot of existing code (400 +) that we need to get into Apex. The majority of this canned code contains one/both: 1) many lines, sometimes containing multiple select statements 2) imbedded create table & view statements (temp user owned). Up until reading your post, I was unable to figure out an easy way of getting this existing code into the product. Thanks. Now the questions, do you know how I would go about dealing with the create tables/views. I've read some posts on this forum which suggest temporary tables being unstable in this environment. Also, do you know if there's a size limitation when passing sql code via a function?
    As you may/may not be able to tell, I'm a bit lost right now... so any info you can provide would be appreciated. Thanks.
    Don

  • Displaying a radio group in SQL QUERY report region

    Good morning everyone,
    I have a report in which a column - ORDER STATUS, will come in with a value of 1, 2 or 3...being order unfilled, order partially filled, or order filled, respectively.
    I would like to display the order status as a radio group on the report so that it will be easy to run down the column of radio buttons to see what is filled, etc.
    I've gone to the manual and checked the doco on HTMLDB_ITEM.RADIOGROUP. But the example given there is actually for CHECKBOX (is this an error?!?).
    I went to the forums and found nothing suitable.
    My region is an SQL QUERY. Can I display the STATUS as a radio group in the SELECT ?
    This is the question.
    Thankyou in anticipation. TC. 23/11/2004

    Tony,
    There may be better solutions, but here's what I was thinking:    create table orders (id number, status number, customer varchar(30))
        insert into orders (id,status,customer) values(1,1,'ACME')
        insert into orders (id,status,customer) values(2,2,'BENSON')
        insert into orders (id,status,customer) values(3,3,'CLARKE')
        commit
        Query Source
        select
          id "ORDER NUMBER",
          decode(status,
            1,htmldb_item.RADIOGROUP(1,status,'1','unfilled')||htmldb_item.RADIOGROUP(2,status,'2','partial','"disabled=true"')||htmldb_item.RADIOGROUP(3,status,'3','filled','"disabled=true"'),
            2,htmldb_item.RADIOGROUP(1,status,'1','unfilled','"disabled=true"')||htmldb_item.RADIOGROUP(2,status,'2','partial')||htmldb_item.RADIOGROUP(3,status,'3','filled','"disabled=true"'),
            3,htmldb_item.RADIOGROUP(1,status,'1','unfilled','"disabled=true"')||htmldb_item.RADIOGROUP(2,status,'2','partial','"disabled=true"')||htmldb_item.RADIOGROUP(3,status,'3','filled'))
          "STATUS",
          customer "Customer Name"
        from orders;Scott

Maybe you are looking for

  • How to write a dynamic SQL in Oracle Portal

    Hello I am running portal on instance C. I have instance A and B From instance C I want to run a report where I will select the instance name. then the when I execute the query must be dynamically generated adn executed. for example: in the case of i

  • Now, I am a believer...

    Back in February when I was going through the process of UPGRADING my old pc into an nForce2 machine, I read this forum on a daily basis.  One thing that caught my eye was that in changing chipsets (VIA to nForce), it's best to do a clean install of

  • How to extract the number of employees (Head count) in a particulr month

    Hi Experts, We are trying to have a customized report  on  Having the  employee  headcount  for a particular month  with number of employees joined on the month and number of employees left the organisation.What is the way to get it. Please advice. V

  • Will not search for a word in pdf file. Using Windows 7

    Like most I have used Acrobat reader for viewing PDF files for years.  I recently upgraded to Windows 7 from XP.  I have tried to search a PDF file for a word and it always comes up with none found even though I search for a word that is displayed in

  • Importing clips of all different shapes and sizes

    I'm completely new to final cut pro and in fact not a film person at all but audio so please be patient. What I'm doing is creating a film montage. The clips I'm compiling together happen to be a few different sizes of widescreen and then some full s