Difference of sql query in SQL Workshop and SQL Report (case when sum(...

Hi ,
I need some help, pls.
The follwg report runs in SQL Workshop - but gives errors in the sql-query report in HTMLDB:
SQL-Workshop:
select
case
when SUM(S.POTENTIAL_GROWTH)> 1 and SUM(S.POTENTIAL_GROWTH) < 4 then 'Ok'
when SUM(S.POTENTIAL_GROWTH)> 4 and SUM(S.POTENTIAL_GROWTH) < 8 then 'SoSo'
when SUM(S.POTENTIAL_GROWTH)> 8 and SUM(S.POTENTIAL_GROWTH) < 12 then 'Very Good'
else 'too much'
end
from "SEGMENTATION" S
In an HTMLDB SQL-Query Report I added Aliases (as requested for HTML) but still gives the error:
<<Query cannot be parsed, please check the syntax of your query. (ORA-00920: invalid relational operator) >>
the code:
select
case
when SUM(S.POTENTIAL_GROWTH) pot_growth > 1 and SUM(S.POTENTIAL_GROWTH)pot_growth < 4 then 'Ok'
when SUM(S.POTENTIAL_GROWTH)pot_growth > 4 and SUM(S.POTENTIAL_GROWTH)pot_growth < 8 then 'SoSo'
when SUM(S.POTENTIAL_GROWTH)pot_growth > 8 and SUM(S.POTENTIAL_GROWTH)pot_growth < 12 then 'Very Good'
else 'too much'
end
from "SEGMENTATION" S
any halp from the gurus wud be very much appreciated.
TIA
Bernhard

Still you did not give the alias for the case when column. For that only you should give the alias
select
case
when SUM(S.POTENTIAL_GROWTH) pot_growth &gt; 1 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 4 then 'Ok'
when SUM(S.POTENTIAL_GROWTH)pot_growth &gt; 4 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 8 then 'SoSo'
when SUM(S.POTENTIAL_GROWTH)pot_growth &gt; 8 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 12 then 'Very Good'
else 'too much'
end "GROWTH"
from "SEGMENTATION" S

Similar Messages

  • Need to run a sql query in the background and display the output in HTML

    Hi Guys,
    I have a link in my iprocurement webpage, when i click this link, a query (sql query) should be run and the output should be displayed in a HTML page. Any ideas of how this can be done. Help appreciated.
    We dont have OA Framework and we r using 11.5.7.
    help needed
    thanx

    Read Metalink Note 275880.1 which has the link to developer guide and personalization guide.

  • Best way to spool DYNAMIC SQL query to file from PL/SQL

    Best way to spool DYNAMIC SQL query to file from PL/SQL [Package], not SqlPlus
    I'm looking for suggestions on how to create an output file (fixed width and comma delimited) from a SELECT that is dynamically built. Basically, I've got some tables that are used to define the SELECT and to describe the output format. For instance, one table has the SELECT while another is used to defined the column "formats" (e.g., Column Order, Justification, FormatMask, Default value, min length, ...). The user has an app that they can use to customize the output...which leaving the gathering of the data untouched. I'm trying to keep this formatting and/or default logic out of the actual query. This lead me into a problem.
    Example query :
    SELECT CONTRACT_ID,PV_ID,START_DATE
    FROM CONTRACT
    WHERE CONTRACT_ID = <<value>>Customization Table:
    CONTRACT_ID : 2,Numeric,Right
    PV_ID : 1,Numeric,Mask(0000)
    START_DATE : 3,Date,Mask(mm/dd/yyyy)The first value is the kicker (ColumnOrder) as well as the fact that the number of columns is dynamic. Technically, if I could use SqlPlus...then I could just use SPOOL. However, I'm not.
    So basically, I'm trying to build a generic routine that can take a SQL string execute the SELECT and map the output using data from another table to a file.
    Any suggestions?
    Thanks,
    Jason

    You could build the select statement within PL/SQL and open it using a cursor variable. You could write it to a file using the package 'UTL_FILE'. If you want to display the output using SQL*Plus, you could have an out parameter as a ref cursor.

  • Pass the result of a SQL Query as table_name  for another SQL Query

    Hi All,
    How to pass the result of a SQL Query as parameter to another SQL Query
    Eg: I am doing the steps below.
    1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
    2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
    Thanks

    Naveen B wrote:
    Hi All,
    How to pass the result of a SQL Query as parameter to another SQL Query
    Eg: I am doing the steps below.
    1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
    2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
    ThanksYou should craete PL/SQL code with cursor which will accept a parameter and call that cursor inside the first one
    But if the first sql returns only one row, you can do it with simple sql code
    select * from (select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ')- - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • Linked Server error: Login Failed for user 'NT AUTHORITY\ANONYMOUS LOGON' between sql server 2005 32 bit and sql server 2012 64 bit

    Hi All,
    Here the linked server is created between sql server 2012 64 bit and sql server 2005 32 bit. I am getting the below error  when i try to access linked server from third server. I have created linked from Instance 1 to Instance 2. When i access it from
    instance 3 i am getting the below error. SPN setting has been done between these 2 servers. Also the option 'Trust the delegate' is enabled for the both the service account. 
    'Login Failed for user 'NT AUTHORITY\ANONYMOUS LOGON' 
    Appreciate your quick response. 
    Vikas.M.S

    Hello,
    Please read the following resources:
    http://www.databasejournal.com/features/mssql/article.php/3696506/Setting-Up-Delegation-for-Linked-Servers.htm
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/ea26de43-4c6b-4991-86d7-e1578f107c92/linked-server-login-failed-for-user-nt-authorityanonymous-logon?forum=sqldataaccess
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How the SQL Query Parsing is processing inside SQL/PLSQL engine?

    Hi all,
    Can you explain how the SQL Query Parsing is processing inside SQL/PLSQL engine?
    Thanks,
    Sankar

    Sankar,
    Oracle Database concepts - Chapter 24..
    You will find the explanation required under the heading parsing.
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14220/sqlplsql.htm

  • SQL Report not showing data - available in SQL Workshop and SQL Developer

    I am having an issue with developing a SQL Report in APEX 3.2.1. I run the code in both SQL developer and SQL Workshop and I get data pulled back (both against my development environment). When I run the same code in a SQL Report region, it returns no data available. Does anyone have any idea what would be causing this? Other regions on the page accessing different tables in the same schema return data without issue. Any help would be appreciated.
    Thanks
    Freddie

    Could you explain the last comment a bit more. Here is a bit more info just in case I touch on the info with it. The db schema is BPAMGR, the Workspace is BPAMGR. We use the same schema for all of our reporting. All of our tables are in the same schema. We don't use any tables outside of this schema. Our APEX workspace has been associated to only this schema. The tables are able to be queried by SQL Workshop in the same APEX instance that the report application is under.
    Freddie

  • Sql query to find answered and received calls for month or day

    Hi  experts !
    1.Any one help in finding out the received, answered and missed ,transfered  in  /  out  calls  in  UCCE  using SQL query for a particular month or day.
    2. We have some  custom report templetes defined ,  need to  know  , how can we  write Sql  query  to  get those  values  from  custum reports.
    due to some issues,  cannot use  webview .

    Hi,
    there's no such thing as reporting "for a particular Team". Teams in ICM are for administration purposes only (to have grouping of agents). ICM does not count the number of calls received by "teams". If there is a report in Webview "by team", it's always by agent. Try to run the report against a team once and then try to remove certain agents from that team - you'll see the difference.
    What you are looking for is either reporting by Agent or by Agent/Skill group combination.
    Try to explore the
    - Agent_Half_Hour
    - Agent_Skill_Group_Half_Hour
    - Skill_Group_Half_Hour
    database views.
    The database schema documents are here:
    http://www.cisco.com/en/US/products/sw/custcosw/ps1844/prod_technical_reference_list.html
    Good luck.
    G.

  • Using a SQL Query in an Alert and Matching a String

    I've created an alert in 12.0.4 using a SQL Query and the field that I'm trying to match is a string.  Originally the query returned multiple rows but when the alert still didn't fire, I modified the query WHERE clause to return only one row:
    NAME                                RESPONSE
    Are area lights working?            No
    My expression in the metric is RESPONSE.  In the Monitor I'm matching a string equal to No.  (Do I need double quotes around the matchvalue?  Single quotes?  No quotes?)  The metric is in the 15min scan group, the role is xMII Developers and I'm in that role. The monitor alert string is ' =  '.  Both metric and monitor are active and I've subscribed to the monitor.  Other alerts in the 15min scan group (all based on tag queries) are firing off properly.
    Why is nothing showing up in the Alert Log?
    David Macindoe

    David,
    Did you figure out the answer?  If not, I will try to find someone to address your question.
    Mike

  • QSUF (Query string url filter) and SQL Server reporting services report viewer parameters

    Hi,
    this is my issue:
    I have a SQL Server reporting services web part on a page with a report with 1 parameter, lets say it's a client list
    Then i have a QSUF that will be used to filter the clients list through the URL
    However, once i connect the filter and the report viewer web part, the parameter goes away and is no longer accessible
    I'd like to somehow keep the parameter visible, in case there is no parameter sent through the URL, i would like the user to be able to choose a client from the parameter drop down list
    I saw that there is a "send empty if no values are passed" option, but i can't seem to get this working properly and i don't know if this option will make the parameter visible again
    Any help would be appreciated
    Thanks.

    Hi,
    According to your post, my understanding is that the query string url filter web part not worked well with SQL server reproting services web part.
    Did you use the Wiki page layout in your environment?
    You can change the page to a web part page, then check whether it work.
    There is a similar thread for your reference.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/4d7584e3-8e1a-48bf-9346-32f8cb480dd1/query-string-url-filter-web-part?forum=sharepointgeneralprevious
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

  • SQL Query returns values like "---" and "NA"

    Hi
              When I execute a sql query in MII it returns values like "---" and "NA" for empty Char and numeric fields respectively.
    I have checked the database and made sure that these fields does not have any value. This happens only when I run the query through MII. Can any one know how can we get rid of these values?
    Thanks in advance
    Shaji

    Shaji,
    MII sets those values as a default if it discovers null values in a query result. You can change this default behaviour in several ways.
    First, have a look at the document [Setting custom null values in XML|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70628af0-8ec4-2c10-7da2-f451e412dd8f?quicklink=index&overridelayout=true]. Then you may also use SQL functions like [NVL|http://www.techonthenet.com/oracle/functions/nvl.php] to change the value directly in the SQL query. You can also change the value inside the MII BLT to whatever you need.
    Michael

  • Sql query to seperate character and number data in a column

    Hi,
    We have a test table on 10.2.0.4 db as below;
    10:44:34 TEST:WAULT > desc t;
    Name Null? Type
    EMP VARCHAR2(10)
    10:43:18 TEST:WAULT > select * from t;
    EMP
    JOHN
    7281
    TOM
    7852145
    BNPPARIBAS
    9862354
    Mindcraft
    875
    INFINITY
    78998775
    01234
    EMP
    0
    -123
    -856359
    SCOTT
    -657
    16 rows selected.
    The question is; we need to segregate the character data and numerical data in the EMP field, using sql query.
    Plz suggest as to how we can achieve this.
    Also, plz suggest how the use of reqexp can be made in this to achieve the same.
    Thanks,
    Rahul

    >
    Hi,
    EMP
    JOHN
    7281
    TOM
    7852145
    The question is; we need to segregate the character data and numerical data in the EMP field, using sql query.
    Plz suggest as to how we can achieve this.Check out the CAST function
    http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/functions015.htm
    However, I would have to ask why on earth you're doing this - it would, IMHO, be
    much better to redesign your app. It looks like you have an EAV problem
    (AKA MUCK or OTLT) Google Joe Celko and these terms.
    Paul...
    Rahul

  • How to replace a dates on a SQL query on Visual Studio (and get the query to work in there in the first place)?

    Morning all,
    I've just been assigned a report-related project but I have not created much of anything in C# or .Net before!
    I was wondering if someone could help me get started. Here are the specifications:
    Basically, I am to create an automated report application. I have the query and I will include it further down
    in this post. The page is to have a couple blanks to specify the Start Date and End Date and replace those dates in the query, and generate the report. What I need some help on is how to make the SQL query work in the application which I will connect to the
    intended database to generate the report (basic I know, but I'm new at this) on Visual Studio 2010. I also need some help on programming the Start Date blank and End Date blank so that what the user types in for those blanks will replace the date fields in
    the SQL query, then generate the report with the new dates. 
    I appreciate the help!
    The SQL query and what the dates are replacing:
    select 
    PTH.INST_ID ,
    PTH.EMPLOYEE_ID,
    DBH.HR_DEDUCTION_AND_BENEFITS_CODE,
    replace(DB.DESCRIPTION,',',''),
    DB.WITHHOLDING_LIABILITY_ACCOUNT_MASK,
    DBH.HR_DEDUCTION_AND_BENEFITS_ID,
    DBH.CHECK_DATE,
    DBH.CHECK_NO,
    DBH.FIN_INST_ACCT_ID,
    replace(replace (DBH.COMMENT,CHAR(10),' '),CHAR(13),' '),
    DBH.HR_DEDUCTION_AND_BENEFIT_CYCLE_CODE,
    DBH.LENGTH,
    DBH.EMPLOYEE_COMPUTED_AMOUNT,
    DBH.EMPLOYEE_BANK_ROUTING_NUMBER,
    DBH.EMPLOYEE_ACCOUNT_TYPE,
    DBH.EMPLOYEE_ACCOUNT_NUMBER,
    DBH.EMPLOYER_COMPUTED_AMOUNT,
    DBH.EMPLOYEE_GROSS_AMOUNT,
    DBH.EMPLOYER_GROSS_AMOUNT,
    DBH.PAYROLL_EXCLUDE,
    PTH.VOID_DATE,
    PTH.BATCH_QUEUE_ID,
    B.BATCH_CODE,
    BQ.FY,
    BQ.END_DATE,
    BQ.COMMENTS,
    BQ.BATCH_CRITERIA_USED,
    BP.COLUMN_VALUE,
    PTH.REPLACEMENT,
    P.LAST_NAME,
    P.FIRST_NAME,
    P.MIDDLE_NAME
    from PY_EMPLOYEE_TAX_HISTORY PTH
    INNER JOIN PERSON_EMPLOYEE PE ON
    PE.INST_ID=PTH.INST_ID AND
    PE.EMPLOYEE_ID=PTH.EMPLOYEE_ID
    INNER JOIN PERSON P ON
    PE.INST_ID=P.INST_ID AND
    PE.PERSON_ID=P.PERSON_ID
    LEFT JOIN HR_EMPLOYEE_DEDUCTIONS_AND_BENEFITS_HISTORY DBH ON
    PTH.INST_ID=DBH.INST_ID AND
    PTH.CHECK_DATE=DBH.CHECK_DATE AND
    PTH.CHECK_NO=DBH.CHECK_NO AND
    PTH.EMPLOYEE_ID=DBH.EMPLOYEE_ID
    LEFT JOIN HR_DEDUCTION_AND_BENEFITS DB ON
    DB.INST_ID=DBH.INST_ID AND
    DB.HR_DEDUCTION_AND_BENEFITS_CODE=DBH.HR_DEDUCTION_AND_BENEFITS_CODE
    LEFT JOIN BATCH_QUEUE BQ ON
    PTH.BATCH_QUEUE_ID=BQ.BATCH_QUEUE_ID
    LEFT JOIN BATCH B ON
    B.BATCH_CODE=BQ.BATCH_CODE 
    LEFT JOIN BATCH_PARAMETER BP ON
    BQ.BATCH_QUEUE_ID=BP.BATCH_QUEUE_ID
    AND BP.COLUMN_NAME = 'SUPPRESS_DIRECT_DEPOSIT'
    ------Please change the WHERE condition for date range of the month you need to run this for.
    WHERE PTH.CHECK_DATE >='07/01/2013'
    AND PTH.CHECK_DATE <='07/31/2013'
    and BQ.BATCH_CODE='BAT_PY_PAYCALC'
    and bq.fy=2014
    ORDER BY PTH.INST_ID ,
    PTH.EMPLOYEE_ID,
    DBH.HR_DEDUCTION_AND_BENEFITS_CODE,
    DBH.CHECK_DATE

    Try this code.  The Server name will be the same name when you use SQL Server Management Studio (SSMS).  It is in the login window for SSMS.  I assume you are using SQLSTANDARD (not SQLEXPRESS) which is in the connection string in the code
    below. I also assume you have remote connection allowed in the database.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    namespace ConsoleApplication1
    class Program
    const string DATABASE = "Enter Database Name Here";
    const string SERVER = "Enter Server Name Here";
    static void Main(string[] args)
    DateTime startDate = DateTime.Parse("07/01/2013");
    string startDateStr = startDate.ToString("MM/dd/yyyy");
    DateTime endDate = new DateTime(startDate.Year, startDate.Month + 1, 1).AddDays(-1);
    string endDateStr = endDate.ToString("MM/dd/yyyy");
    string connStr = string.Format("Server={0}\\SQLSTANDARD;Database={1};Trusted_Connection= True;", SERVER,DATABASE);
    string SQL = string.Format(
    "select\n" +
    " PTH.INST_ID\n" +
    ",PTH.EMPLOYEE_ID\n" +
    ",DBH.HR_DEDUCTION_AND_BENEFITS_CODE,\n" +
    ",replace(DB.DESCRIPTION,',','')\n" +
    ",DB.WITHHOLDING_LIABILITY_ACCOUNT_MASK\n" +
    ",DBH.HR_DEDUCTION_AND_BENEFITS_ID\n" +
    ",DBH.CHECK_DATE\n" +
    ",DBH.CHECK_NO\n" +
    ",DBH.FIN_INST_ACCT_ID\n" +
    ",replace(replace (DBH.COMMENT,CHAR(10),' '),CHAR(13),' ')\n" +
    ",DBH.HR_DEDUCTION_AND_BENEFIT_CYCLE_CODE\n" +
    ",DBH.LENGTH\n" +
    ",DBH.EMPLOYEE_COMPUTED_AMOUNT\n" +
    ",DBH.EMPLOYEE_BANK_ROUTING_NUMBER\n" +
    ",DBH.EMPLOYEE_ACCOUNT_TYPE\n" +
    ",DBH.EMPLOYEE_ACCOUNT_NUMBER\n" +
    ",DBH.EMPLOYER_COMPUTED_AMOUNT\n" +
    ",DBH.EMPLOYEE_GROSS_AMOUNT\n" +
    ",DBH.EMPLOYER_GROSS_AMOUNT\n" +
    ",DBH.PAYROLL_EXCLUDE\n" +
    ",PTH.VOID_DATE\n" +
    ",PTH.BATCH_QUEUE_ID\n" +
    ",B.BATCH_CODE\n" +
    ",BQ.FY\n" +
    ",BQ.END_DATE\n" +
    ",BQ.COMMENTS\n" +
    ",BQ.BATCH_CRITERIA_USED\n" +
    ",BP.COLUMN_VALUE\n" +
    ",PTH.REPLACEMENT\n" +
    ",P.LAST_NAME\n" +
    ",P.FIRST_NAME\n" +
    ",P.MIDDLE_NAME\n" +
    " from PY_EMPLOYEE_TAX_HISTORY PTH\n" +
    " INNER JOIN PERSON_EMPLOYEE PE ON\n" +
    " PE.INST_ID=PTH.INST_ID AND\n" +
    " PE.EMPLOYEE_ID=PTH.EMPLOYEE_ID\n" +
    " INNER JOIN PERSON P ON\n" +
    " PE.INST_ID=P.INST_ID AND\n" +
    " PE.PERSON_ID=P.PERSON_ID\n" +
    " LEFT JOIN HR_EMPLOYEE_DEDUCTIONS_AND_BENEFITS_HISTORY DBH ON\n" +
    " PTH.INST_ID=DBH.INST_ID AND\n" +
    " PTH.CHECK_DATE=DBH.CHECK_DATE AND\n" +
    " PTH.CHECK_NO=DBH.CHECK_NO AND\n" +
    " PTH.EMPLOYEE_ID=DBH.EMPLOYEE_ID\n" +
    " LEFT JOIN HR_DEDUCTION_AND_BENEFITS DB ON\n" +
    " DB.INST_ID=DBH.INST_ID AND\n" +
    " DB.HR_DEDUCTION_AND_BENEFITS_CODE=DBH.HR_DEDUCTION_AND_BENEFITS_CODE\n" +
    " LEFT JOIN BATCH_QUEUE BQ ON\n" +
    " PTH.BATCH_QUEUE_ID=BQ.BATCH_QUEUE_ID\n" +
    " LEFT JOIN BATCH B ON\n" +
    " B.BATCH_CODE=BQ.BATCH_CODE\n" +
    " LEFT JOIN BATCH_PARAMETER BP ON\n" +
    " BQ.BATCH_QUEUE_ID=BP.BATCH_QUEUE_ID\n" +
    " AND BP.COLUMN_NAME = 'SUPPRESS_DIRECT_DEPOSIT'\n" +
    " WHERE PTH.CHECK_DATE >='{0}'\n" +
    " AND PTH.CHECK_DATE <='{1}'\n" +
    " and BQ.BATCH_CODE='BAT_PY_PAYCALC'\n" +
    " and bq.fy=2014\n" +
    " ORDER BY PTH.INST_ID\n" +
    ",PTH.EMPLOYEE_ID\n" +
    ",DBH.HR_DEDUCTION_AND_BENEFITS_CODE\n" +
    ",DBH.CHECK_DATE", startDateStr, endDateStr);
    SqlDataAdapter adapter = new SqlDataAdapter(SQL, connStr);
    DataTable dt = new DataTable();
    adapter.Fill(dt);
    jdweng
    Could you elaborate more on what this code does in general?
    Does it generate a table with the data between specified dates? If so, where is the table shown? 
    Where does one enter in the specified start and end dates on the Web Application? Do I have to create start and end date blanks and link them to the code for it to work?
    Sorry for the inconvenience - I'm just really new at this. Thanks!

  • SQL query using Group by and Aggregate function

    Hi All,
    I need your help in writing an SQL query to achieve the following.
    Scenario:
    I have table with 3 Columns. There are 3 possible values for col3 - Success, Failure & Error.
    Now I need a query which can give me the summary counts for distinct values of col3 for each GROUP BY of col1 and col2 values. When there are no values for col3 then it should return ZERO count.
    Example Data:
    Col1 Col2 Col3
    abc 01 success
    abc 02 success
    abc 01 success
    abc 01 Failure
    abc 01 Error
    abc 02 Failure
    abc 03 Error
    xyz 07 Failure
    Required Output:
    c1 c2 s_cnt F_cnt E_cnt (Heading)
    abc 01 2 1 1
    abc 02 1 1 0
    abc 03 0 0 1
    xyz 07 0 1 0
    s_cnt = Success count; F_cnt = Failure count; E_cnt = Error count
    Please note that the output should have 5 columns with col1, col2, group by (col1,col2)count(success), group by (col1,col2)count(failure), group by (col1,col2)count(error)
    and where ever there are NO ROWS then it should return ZERO.
    Thanks in advance.
    Regards,
    Shiva

    Hi,
    user13015050 wrote:
    Thanks TTT. Unfortunately I cannot use this solution because I have huge data for this.T's solution is basically the same as mine. The first 23 lines just simulates your table. Since you actually have a table, you would start with T's line 24:
    SELECT col1 c1, col2 c2, SUM(decode(col3, 'success', 1, 0)) s_cnt, ...
    user13015050 wrote:Thanks a lot Frank. It helped me out. I just did some changes to this as below and have no issues.
    SELECT     col1
    ,     col2
    ,     COUNT ( CASE
              WHEN col3 = 'SUCCESS'
              THEN 1
              END
         )          AS s_cnt
    ,     COUNT ( CASE
              WHEN col3 = 'FAILED'
              THEN 1
              END
         )          AS f_cnt
    ,     COUNT ( CASE
              WHEN col3 = 'ERROR'
              THEN 1
              END
         )          AS e_cnt
    FROM     t1
    WHERE c2 in ('PURCHASE','REFUND')
    and c4 between to_date('20091031000000','YYYYMMDDHH24MISS') AND to_date('20100131235959','YYYYMMDDHH24MISS')
    GROUP BY c1, c2
    ORDER BY c1, c2;
    Please let me know if you see any issues in this query.It's very hard to read.
    This site normally compresses spaces. Whenever you post formatted text (such as queries or results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    Also, post exactly what you're using.  The code above is SELECTing col1 and col2, but there's no mention of either in the GROUP BY clause, so I don't believe it's really what you're using.
    Other than that, I don't see anything wrong or suspicious in the query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Vendor payment and customer recipts across company codes

    Hi all, We are having 4 company codes in US.The vendors and customers are spread across company codes. 1st scenario: Vendor "abc" has a debit balance os 5000 in company code A. In company code B, the same vendor has credit balance of 10000. How can w

  • Keynote 6.0 Images Disappearing

    We do a lot of work within Keynote 6.0 and every time we add a new images to the presentation all other images disappear and we are left with a grey box with a cross and a question mark. It doesn't do this to all presentations but quite a lot, and al

  • Thread problem.. help

    I have a thread execution of my program which reading a text file and in the same time giving the priority to the GUI. My problem is, if I comment the:       m_Support.firePropertyChange("", null, null);in the method "setWorkingInstances", my GUI wil

  • Last argument in AGO function

    Hi Everyone... Hope everyone is good . So we have this requirement where user want to see selected quarter last month, then previous quarter last month and previous year last month based on Year and Quarter selection. for example. Prompts: Year - 201

  • Copy command hangs

    Hello All, I'm having problems copying data between oracle 8.1.6.1 dbs, both running on Red Hat 6.2. I'm using syntax like copy from username/password@server - insert applications - using select * from applications This works fine when copying betwee