{Urgent} Query Output

Hi all,
I have the following simple table. I'm using the LISTAGG function.
The output of my query is :
100,200,300,400,500,600
102,302,602
403,503
If you notice for the id 2 and 3 there are missing data because they do not exist.
I would like the output to be :
100,200,300,400,500,600
102, ,302, ,602
, ,  ,403,503
Thank you
CREATE TABLE test
   id    INTEGER,
   yr    INTEGER,
   val   INTEGER
INSERT INTO test (id, yr, val)
     VALUES (1, 2005, 100);
INSERT INTO test (id, yr, val)
     VALUES (1, 2006, 200);
INSERT INTO test (id, yr, val)
     VALUES (1, 2007, 300);
INSERT INTO test (id, yr, val)
     VALUES (1, 2008, 400);
INSERT INTO test (id, yr, val)
     VALUES (1, 2009, 500);
INSERT INTO test (id, yr, val)
     VALUES (1, 2009, 600);
INSERT INTO test (id, yr, val)
     VALUES (2, 2005, 102);
INSERT INTO test (id, yr, val)
     VALUES (2, 2007, 302);
INSERT INTO test (id, yr, val)
     VALUES (2, 2009, 602);
INSERT INTO test (id, yr, val)
     VALUES (3, 2008, 403);
INSERT INTO test (id, yr, val)
     VALUES (3, 2009, 503);
  SELECT LISTAGG (val, ',') WITHIN GROUP (ORDER BY yr)
    FROM test
   WHERE YR BETWEEN 2005 AND 2010
GROUP BY id;

Maybe NOT TESTED! LISTAGG states: Null values in the measure column are ignored.
select listagg(decode(val,null,'_',to_char(val)),',') within group (order by yr) 
  from (select t.id,t.val,y.yr 
          from test t partition by (t.id) 
               right join 
               (select level + 2004 yr 
                  from dual 
                connect by level <= 6
               ) y 
            on y.yr = t.yr
group by id
Regards
Etbin

Similar Messages

  • URGENT - Query to get employes with multiple cost center

    Hello,
    The sample data for my requirement is:
    create table a
    (year     number(4),
    month      number(2),
    empno number(5),
    cost_center number(3)
    insert into a values(2003, 10, 1034, 102);
    insert into a values(2003, 10, 1034, 102);
    insert into a values(2003, 10, 1034, 102);
    insert into a values(2003, 10, 1034, 103);
    insert into a values(2003, 10, 1034, 103);
    insert into a values(2003, 10, 1039, 102);
    insert into a values(2003, 10, 1039, 102);
    insert into a values(2003, 10, 1070, 102);
    insert into a values(2003, 10, 1070, 103);
    commit;
    In the above sample data, empno 1034 & 1070 has two different cost centers (102 & 103) whereas empno 1039 has one only cost center i.e. (102).
    Now I want a query that returns empno, cost_center with employees having more than one cost center. Considering the above sample data, the query should return empno 1034 & 1070. Empno 1039 should not appear in the query output as it has only cost center.
    The output should be something like...
    Empno cost_center
    1034 102
    1034 103
    1070 102
    1070 103
    I'll b grateful for an urgent reply.
    HASAN.

    select distinct empno, cost_center
    from a a1
    where exists (select 1 from a a2
    where a2.empno = a1.empno
    having count(distinct cost_center) > 1)
    /

  • Central Management server - executed a query but how to send the query output in the form of mail?

    Hi All,
    i have used CMS in SQL 2008 R2. i have added couple of servers in its group. i have executed a query & i need to send the query output in the form of email.
    basically query is checking the rows count from couple of user tables in servers.
    issue here is how to copy the data that is used by CMS? i need to work on automate the rows count in difft user table in db servers
    could you please suggest how can i achieve this?

    Copy to what?
    SELECT COUNT(*) FROM sys.objects
    Running the above statement returns two columns (server name and count)
    All the servers SS2005  and onwards , then use
    EXEC msdb.dbo.sp_send_dbmail 
         @profile_name = 'name', 
         @recipients = '[email protected]', 
         @query = 'SELECT COUNT(*) FROM sys.objects', 
         @subject = 'Count rows'
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • ERROR displaying in the query output... urgetn

    hi experts,
    For the amount keyfigures in the query output it displaying ERROR after the amount like ex- 2000 ERROR.
    plz let me know how to rectify this..
    regards
    vadlamudi

    hi,
    i have created only two keyfigures EMP_BASIC and EMP_HRA. and in the transformations i have mapped with 0DOC_CURRCY.
    but in the report its showing ERROR only after the amount. plz tell me exactly with what field i need to map???
    regards
    vadlamudi

  • Issue In query output

    Hello Gurus,
    I am having an issue with query output.Please find below the details of it
    Unsold claims: Total---> 200
    Dispatch: Total--->118,086
    Unsold claims/dispatch--->0.001694
    This should be the output but its coming --.0033120 because itu2019s dividing with max value in dispatch which is 60,386.
    Reason: The aggregation property of Dispatch is max value. I am not supposed to do any changes in Modeling. So can we do any thing at reporting level to get the desired output?
    Desired output---->0.001694
    Output coming---->.0033120
    Please help me in getting the desired output at query level.
    Regards,

    solved with the help of nested exception aggregation

  • Change layout of Adhoc query output list for Custom infotype

    Hi All,
    The fields in the Infoset query output on a custom infotype are aligned with the fields u2018payment typeu2019 and u2018amountu2019 appearing repeatedly(in columns) as declared in the Infotype and the output will be a long horizontal list.
    Instead, the requirement is that the output list should show vertically so that If I choose u2018Payment Typeu2019 and u2018Amountu2019 as output fields, it will show a long vertical list as in the case of a standard infotype (IT0008).
    Also, this way enables user to use Payment Type as a selection criteria so as to just pulling the needed payment type. When we use IT0008 in the infoset it works fine but in custom IT it does not work.
    Any pointers/suggestions on how we can achieve this would be helpful.

    Hi yu liang,
                     You can find vendor list having Vendor No. & without showing total liability for every vendor.
    after executing the report,
    1.You need to select "change layout (ctrl+F8)",
    a small window comes, it has two part -> column content & hidden fields.
    then u select "Vendor" from hidden field & move it to column content.
    2. at column content there is a column named "Total". u need to remove check for your column name "amount".
    now select "copy" button or enter. u will find the req. report.
    u can save it also by ur name.
    hope its helpful to u.......
    plz, reward points as a way of thanks if helpful...

  • To download the query output to falt file

    Hi all,
    i have a query which i know will give more than 65k records as the output for a selection.
    i cannot run this query in excel due to its limitation.
    if i run on web i cannot download this as downloading is happening to excel file only.
    The customer ideally wants to download the query result to a text file(csv,tab-delimited etc) which inturn it will upload to MS-Access.
    How do i achieve this?
    SAP has given response use try using these options:
    1.open interfaces to receive the output of a query via the MDX language.
    2.open hub tool as it is designed for big amounts of data.(i suppose this is not possible as i want to download query output not the data target contents)
    how do i achieve my scenario with option 1?
    Are there any alternatives??
    Any useful help will be rewarded.
    Regards,
    Dhanya.

    hi vivek,
    thnks for the useful reply.
    i have some problem with my ID,hence loggin in through my coleague's ID.
    i will assign u points as i get logged in.
    I did as u said by downloading it to unconverted format.
    the file got download to a text file.where the output has
    1.header rows(10 lines almost)
    2.the values r coming in single quotes e,g:
    '144000023073      'TAAS SETTLEMENT CONV 738 '19333000   '30.09.2006          '0.000
    how can i remove all this?
    Regards,
    Dhanya
    I

  • How to get the Query output to Excel

    Hi ,
    Can you tell me how to get the Query output to excel with out using any third party tool?
    Can you tell me how to write the code in Webservice and call it..
    Please explain it Elaboartly..
    Thanks in Advance!!!
    Mini

    whats your source system?
    you can use Live office, or query as a webservice if you are getting data from universe
    if you're getting data from SAP BI query and you have a java stack on your netweaver then you can get the data directly using sap bi connector in xcelsius.
    good luck

  • Query Output to download in flat file through APD  or other means?

    Hello Experts,
    I am currently on BW3.5 system and have requirement to load query output in flat file in .csv format. I checked the option of APD but looks like we cant directly load the query output in flat file like in APD (BW  3.5 system) .
    One way i can think of it...load  the query output in transactional ODS and built an infospoke on it to write into flat file.
    Please advice if there are any better methods to store the query output in flat files.
    Thanks!

    Hi,
    Use RSCRM_BAPI.
    See
    Re: RSCRM_Bapi
    See the help on RSCRM_BAPI
    Re: Running Quaries automatically and saving them in as a Excel file in Server
    Re: Data transfer to external systems
    Re: Loading from a Custom R/3 Table
    Re: How can I schedule my Bex report to execute in background
    Re: How can I insert the RSCRM_BAPI into Process chain?
    Thanks
    Reddy

  • How to replace # or Not assigned with blank in BEx Query Output.

    Hi,
    While running the query through BEx Query desginer or Anlayser, I am getting # or Not assigned where there are no values.
    The requirement is to "Replace # or Not assigned with a blank" in the output.
    I want to know, is there any setting in BEx query desginer where we can do this. How to do this.
    Please share your inputs on this. Any inputs on this would be appreciated.
    Thanks,
    Naveen

    Check out SDN-thread: "Re: Remove 'Not assigned'" for more details
    Ideas from SDN research:
    "a solution i have used is to put each RKF column in a CKF colum then in each CKF use RKF + 0, the outcome is that your # should now be 0s, in the query properties you can set the option to display 0s as blank."
    "try to enter a text for the blank entry in the master data maintenance of the relevant objects and set the display option for the objects to 'text'."
    Threads:
    SDN: How to replace # or Not assigned with blank in BEx Query Output.
    SDN: Re: Remove 'Not assigned
    SDN: How to replace # or (Not assigned) with blank in BEx Query Output.
    SDN: Bex Analyzer : Text element system's table ?  
    SDN: change message in web application designer ["nonavailable" ->  136 of SAPLRRSV]
    SDN: Not Assigned ["Not Assigned -> 027 of SAPLRRSV]
    SDN: replacing '#'-sign for 'not assigned' in queries
    SDN: # in report when null in the cube
    SDN: How to replace '#' with blank when there is no value for a date field
    Edited by: Thomas Köpp on Sep 13, 2010 5:20 PM

  • Urgent query JDBC on linux

    I have an urgent query . I have written a java code on microsoft platform that talks with SQL server 2000 hosted on windows200 machine in a network using JDBCODBC driver wothou using a Data source name.
    But this same code when i try to run on mandrake linux throws an exception as
    java.sql.SQLException: [unixODBC] [Driver Manager] Data source name not found,
    and no default driver specified.

    MS provides a JDBC driver for MSSQL 2000, go to there site and download it.

  • How to store select query output in arrays.

    i created a varray type variables and now want to assign some data though select query output in pl/sql code as well as in reports 6i.

    You're in the wrong forum (this one is for issues with the SQL Developer tool). You were in the right one where you posted first, but don't reuse unrelated threads as you did.
    Regards,
    K.

  • Output mismatch between BEx query output and WebI Report output

    Hi All,
    I have a BEx query in which there are only characteristics placed in rows.
    There are combinations of the values of the characteristics giving different records in the query output.
    Date is one of the characterisctics in the query output.
    There is an output mismatch between the query output and the WebI report output in the following case:
    When there are 'Not Assigned' or '#' or blank values, there are additional entries(rows) in the WebI report, giving repeating or wrong entries in the Date field. This is incorrect data.
    Is this because of the  'Not Assigned' or '#' or blank values of the Characteristics or is there any other reason?
    How do I fix this?
    Please helo me with this.
    Thanks and Regards,
    Srilakshmi B

    Hi Rajesh,
    I need to verify the WebI report output for records with # and 'Not assigned' values for the cHracteristics in the report.
    So I cannot check the WebI report by hiding the # or Not assigned values.
    The problem is that in the Query output the records are like these shown below:
    Char1                    CHar2                          CHar3                       Date field
    A                             B                                 C                                Date1
    #(Not assgined)      #(Not assgined)      #(Not assgined)             No value
    Where as the WebI report output is as below:
    Char1                    CHar2                          CHar3                       Date field
    A                             B                                 C                                Date1
    #(Not assgined)      #(Not assgined)      #(Not assgined)            Date1
    As shown here, there are wrong/repeating entries for the Date field in the WebI report output.
    Please check this and let me know what could be the issue and how do I fix it.
    Thanks and Regards,
    Srilakshmi B

  • Query output transfer to excel file

    hi all,
    how can i query output transfer to excel file ? i am not using any tool. please suggest me. is there any method that i transfer that output to excel file?

    You can create a csv file. See dump_csv function from Tom Kyte.

  • Want to See Selected Input Variables in the query output

    Hi al
    My client gives a requirment like they want to see selected variables in the query output. Like suppose if i am  entering Profit center, controlling area, version, caldayas a input on the screen. Now they want to see only Profit center and version on the query result.
    Please let me know if any one has this solution.
    Regards,
    Amit Shetye

    Hi
    Can you please give us user requirement and according to ure requirement so we given replies . If ure requirement please explain detail
    But it is not neccessary that we can put something in free char and all. Inspite of that they wanted to select the input variable as per their requirement. They dont want to restrict them in Free char.

Maybe you are looking for

  • Abt Drop Down For ALV Data cells

    Hi, I m unable to create drop down for each cell of ALV table. Reply me as soon as possible. Thks.

  • JDBC Reaciver

    Hi Guys, I have a problem when i am  passing a message from Idoc to Oracle  useig JDBC Reaciver i had problem in Runtime.. Below message  is my Error message.. channel Jdbc_Rec: processing started; party  , service DMZ_DEV 2006-09-07 11:56:33 Error N

  • Failed Messages In Adapter Engine in Pi 7.1 EHP1

    Hi All , We have observed that Java stack AE  shows some error messages, but when we tried to open those failed messages, shows they were already processed successfully. And observed that this case is only happens in java stack only, we couldn't find

  • Smart Dialing

    Hello All Apparently my Classic which I bought yesterday doesn't have the "Smart Dialing" menu. I don't know what to do. I want to add local number limit but i can't. The phone doesn't show the caller ID and shows only the numbers. Help me please Ima

  • [ Solved ] World of Warcraft problem - resolution panning

    I decided to give Wow a try and the game runs alright good at native resolution but if I set it to a lower resolution, the resolution changes but the screen goes into panning mode.  I think the resolution becomes 800x600 and then moving the mouse dow