Query for required format

my table data
no name address
================
10 aaa pune
10 aaa mumbai
20 bbb chennai
20 bbb hyd
i want the output as below
no name address1 address2
=========================
10 aaa pune mumbai
20 bbb chennai hyd
please anybody help on this

What is your DB version?
What if there are more than two addresses for a person? Do you expect a column address_3?
FAQ: {message:id=9360002}
You are looking for some kind of pivoting, and the answer is here, below
Read FAQ: {message:id=9360005}
The FAQ link above has almost all the way to do static and dynamic pivoting.. Go throuth the same, try yourself - if you are facing an issue, put the specific question in this forum along with your code..
Edited by: jeneesh on Nov 15, 2012 2:14 PM

Similar Messages

  • Query for particular format

    I am looking for a way to verify that data in a column adheres to a specific format.
    In this case I want to query the telephone column in the client table to verify that is in the following format:
    (555) 555-5555
    We have an inbound data feed that has numbers in all sorts of formats.  I am not sure what type of function I could use here or what I could put in my where clause for this.
    Thanks!

    phone_nbr CHAR(12) LIKE '([0-9][0-9][0-9]) [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]'
    However, it would be better to use the  International
    Telecommunication Union standard E.123.
    Display formatting should be done in the  front end, not the database. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Logic- for required format output

    Hi,
    I have a situation where material number has multiple entries(rows).
    I required to show only single row output some of the respective material number quantity fields  needs to be ADDED and some of the quantity should be same as a single row field value.
    example :
    following  below code gives us  output
    <b>'Material'    'Quant1'    'Quant2'</b>
    1000-A                                 10                999
    1000-A          20           999
    1000-B          10           700
    1000-B          20           700
    1000-B          30           700
    but i need output in 2 lines only.
    <b>'Material'    'Quant1'    'Quant2'</b>
    1000-A            30             999
    1000-B            60             700
    i.e Quant1 values should be added and Quant2 values should remain same.
    report x.
    data: begin of itab occurs 0,
    matnr(10) type c,
    quant1(4) type c,
    qunat2(4) type c,
    end of itab.
    itab-matnr = '1000-A'.
    itab-quant1 = '10'.
    itab-quant2 = '999'.
    APPEND itab.
    itab-matnr = '1000-A'.
    itab-quant1 = '20'.
    itab-quant2 = '999'.
    APPEND itab.
    itab-matnr = '1000-B'.
    itab-quant1 = '10'.
    itab-quant2 = '700'.
    APPEND itab.
    itab-matnr = '1000-B'.
    itab-quant1 = '20'.
    itab-quant2 = '700'.
    APPEND itab.
    itab-matnr = '1000-B'.
    itab-quant1 = '30'.
    itab-quant2 = '700'.
    APPEND itab.
    write : /10 'Material' , 30 'Quant1' , 45 'Quant2' .
    loop at itab.
    write : /10 itab-matnr , 30 itab-quant1 , 45 itab-quant2 .
    endloop.
    Any ideas?
    Regards
    Praveen

    Hi,
    Please try this.
    data: wa_itab like itab.
    sort itab by matnr.
    loop at itab.
      move itab to wa_itab.
      at end of matnr.
        sum.
        write : /10 wa_itab-matnr , 30 itab-quant1 , 45 itab-quant2 .
      endat.
    endloop.
    Regards,
    Ferry Lianto

  • Query for required out put as mention below in SQL

    HAI..
    all
    I HAVE A TABLES LIKE
    SQL> SELECT *FROM A;
    PCK PN
    1 BIKES
    2 COMPONENTS
    SQL> SELECT *FROM B;
    PSC PCK SBNAME
    1 1 RASEBAIKE
    2 1 SPEEDBIKE
    3 2 MOTHERBORD
    4 2 HARDIDSK
    5 1 SPORTSBIKE
    6 2 RAM
    SQL> SELECT PN,SBNAME,COUNT(*) FROM A,B WHERE A.PCK=B.PCK GROUP BY ROLLUP(PN,SBNAME);
    PN SBNAME COUNT(*)
    BIKES RASEBAIKE 1
    BIKES SPEEDBIKE 1
    BIKES SPORTSBIKE 1
    BIKES 3
    COMPONENTS RAM 1
    COMPONENTS HARDIDSK 1
    COMPONENTS MOTHERBORD 1
    COMPONENTS 3
    6
    I want output like this how to avoid duplicates in PN column in SQL
    OUTPUT
    1 BIKES
    1 RASEBAIKE
    2 SPEEDBIKE
    5 SPORTSBIKE
    2 COMPONENTS
    3 MOTHERBORD
    4 HARDIDSK
    6 RAM

    Kindly place \ before and after your data and code \try this
    with a as
      select 1 pck, 'BIKES' pn from dual union
      select 2, 'COMPONENTS' from dual
    , b as
      select 1 psc, 1 pck, 'RASEBAIKE' sbname from dual union
      select 2, 1, 'SPEEDBIKE' from dual union
      select 3, 2, 'MOTHERBORD' from dual union
      select 4, 2, 'HARDIDSK' from dual union
      select 5, 1, 'SPORTSBIKE' from dual union
      select 6, 2, 'RAM' from dual
    select case
                when nvl(a.pn, 'ALL') = lead(a.pn) over (partition by a.pn order by a.pn) then
                  null
                else
                  nvl(a.pn, 'ALL')
           end pn
          ,b.sbname
          ,count(*)
    from a, b
    where a.pck = b.pck
    group by rollup(a.pn, b.sbname)
    PN         SBNAME       COUNT(*)
               RASEBAIKE           1
               SPEEDBIKE           1
               SPORTSBIKE          1
    BIKES                          3
               HARDIDSK            1
               MOTHERBORD          1
               RAM                 1
    COMPONENTS                     3
    ALL                            6if you want the output as follows:
    PN         SBNAME       COUNT(*)
    BIKES      RASEBAIKE           1
               SPEEDBIKE           1
               SPORTSBIKE          1
                                   3
    COMPONENTS HARDIDSK            1
               MOTHERBORD          1
               RAM                 1
                                   3
    ALL                            6then simply modify LEAD to LAG

  • Formatted Search query for Vacation Accrued

    Hi Experts,
    I have a Client who needs to keep tract on the Vacation Accrued on the Employee Master Data. I have created this UDF on the Master Data, but I could not get the query for the Formatted Search right.
    This Formatted search on the UDF ( must look at the OHEM.startDate field and populate the following:
    If it is a still within year of the system date, it must populate 0,
    If it is > 1 year and < 3 years, it must populate 5,
    etc.
    Any help would be greatly appreciated.
    Marli

    Hi Experts,
    Here is what I did for the query mentioned above:
    {SELECT
    CASE
               WHEN (T0.startDate > GETDATE() -356)
                       THEN 0
               WHEN (T0.startDate > GETDATE() - 712)
                       THEN 5
    END
    As 'Vacation Accrued'
    FROM OHEM T0}
    The issue is that if I link this query to the UDF on the EMD, I get a list of 0 and 5 to choose from. I need to populate automatically.
    Thanks.
    Marli

  • Input Value long enough for date format ,Error in executing parallel query

    Hi,
    My Table: ANML( ID, STATUS,B_DATE,B_MONTH,B_YEAR, DEATH_DATE)
    status 1 for alive and 2 for dead.
    i wrote a view to get age.
    as
    create or relace view view1 as
    select top."ID",top."STATUS",top."DOB",top."DEATH_DATE",top."ANML_AGE",top."DAYSDIFF",
    CASE
    WHEN anml_age < 1
    THEN 'D'
    ELSE 'M'
    END age_unit,
    CASE
    WHEN anml_age < 1
    THEN TO_CHAR (daysdiff || ' Day(s)')
    WHEN anml_age < 12
    THEN TO_CHAR (anml_age || ' Month(s)')
    WHEN MOD (anml_age, 12) = 0
    THEN TO_CHAR (ROUND (anml_age / 12, 0) || ' Year(s) '
    ELSE TO_CHAR ( ROUND (anml_age / 12, 0)
    || ' Year(s) '
    || MOD (anml_age, 12)
    || ' Month(s)'
    END age_string
    from
    (SELECT a.*,
    CASE WHEN status IN ( 1)
    THEN FLOOR(MONTHS_BETWEEN(TRUNC(SYSDATE),dob))
    WHEN death_date IS NOT NULL AND status IN (2)
    THEN FLOOR(MONTHS_BETWEEN(death_date,dob))
    END anml_age,
    CASE WHEN status IN (1)
    THEN FLOOR(TRUNC(SYSDATE)-TRUNC(dob))
    WHEN death_date IS NOT NULL AND status IN (2)
    THEN FLOOR(TRUNC(death_date) - TRUNC(dob))
    END daysdiff
    from (
    SELECTanml.id, status,
    TO_DATE ( DECODE (b_date,
    NULL, 1,
    b_date
    || '-'
    || DECODE (b_month,
    NULL, 1,
    b_month
    || '-'
    || b_year,
    'dd-mm-yyyy'
    ) DOB,
    death_date
    FROM anml
    WHERE b_year IS NOT NULL
    ) a) top
    when i tried to fetch all values from view its working fine.
    But when i tried to fetch values based on condition like as follows,
    select * from view1 where anml_age > 20 and anml_age<30
    I am getting error like:
    Input Value long enough for date format and Error in executing parallel query
    Please tell me wht is wrong.

    Here is your formatted code
    create or relace view view1 as
    select top."ID",top."STATUS",top."DOB",top."DEATH_DATE",top."ANML_AGE",top."DAYSDIFF",
    CASE
    WHEN anml_age < 1
    THEN 'D'
    ELSE 'M'
    END age_unit,
    CASE
    WHEN anml_age < 1
    THEN TO_CHAR (daysdiff || ' Day(s)')
    WHEN anml_age < 12
    THEN TO_CHAR (anml_age || ' Month(s)')
    WHEN MOD (anml_age, 12) = 0
    THEN TO_CHAR (ROUND (anml_age / 12, 0) || ' Year(s) '
    ELSE TO_CHAR ( ROUND (anml_age / 12, 0)
    || ' Year(s) '
    || MOD (anml_age, 12)
    || ' Month(s)'
    END age_string
    from
    (SELECT a.*,
    CASE WHEN status IN ( 1)
    THEN FLOOR(MONTHS_BETWEEN(TRUNC(SYSDATE),dob))
    WHEN death_date IS NOT NULL AND status IN (2)
    THEN FLOOR(MONTHS_BETWEEN(death_date,dob))
    END anml_age,
    CASE WHEN status IN (1)
    THEN FLOOR(TRUNC(SYSDATE)-TRUNC(dob))
    WHEN death_date IS NOT NULL AND status IN (2)
    THEN FLOOR(TRUNC(death_date) - TRUNC(dob))
    END daysdiff
    from (
    SELECTanml.id, status,
    TO_DATE ( DECODE (b_date,
    NULL, 1,
    b_date
    || '-'
    || DECODE (b_month,
    NULL, 1,
    b_month
    || '-'
    || b_year,
    'dd-mm-yyyy'
    ) DOB,
    death_date
    FROM anml
    WHERE b_year IS NOT NULL
    ) a) top

  • Formatted Search Query for BatchNo

    Dear All,
    I am using the following query as formated search for Identifying the batches availble during the creation of  Delivary document
    in a user defined column at row level. When i click on this field it's showing the Batches for the Item with Zero Qty also.
    I need to display only the batches where the QTY >0. This query displaying even the Zero Qty Batches also. Please help me to modify the below query for getting the above. Below is the  query .
    SELECT distinct  T4.[BatchNum] FROM [dbo].[OIBT]  T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN DLN1 T2 ON T1.ItemCode = T2.ItemCode INNER JOIN ODLN T3 ON T2.DocEntry = T3.DocEntry INNER JOIN IBT1 T4 ON T0.BatchNum = T4.BatchNum AND T3.DocNum = T4.BaseNum INNER JOIN OWHS T5 ON T0.WhsCode = T5.WhsCode WHERE T0.[ItemCode] = $[$38.1] AND  T4.[WhsCode] = $[$38.24] AND T0.[Quantity]>=$[$38.11]
    Regards
    Srini

    i removed that T5, But It's  showing the  Batches where the qty in the main warehouse for that batch is Zero.That batch was actually present in another warehouse. And also when i am working on other warehouses it's showing the batches in the main warehouse where the qty is present.
    Regards
    Srini
    Edited by: Srini on May 11, 2010 10:24 PM

  • Formatted search query for displaying invoice items details

    hi all,
    i need to display all the items in AP invoice.kindly suggest me a query for that.
    in AP invoice
    Ex. row items
    code--descqtyprice--
    total
    I0001--XXXXXXX5--
    100 -
    500
    query should display this row as
    code--desc--
    price
    I0001--XXXXXXX--
    100
    I0001--XXXXXXX--
    100
    I0001--XXXXXXX--
    100
    I0001--XXXXXXX--
    100
    I0001--XXXXXXX--
    100
    =================================
    the query should display as the qty is 5 so it will display the same item 5 times
    kindly suggest me some query for formatted search
    its very urgent
    regards
    sandip

    Hi Sandip,
    DoQuery("Select b.ItemCode from OINV a,INV1 b Where a.DocEntry=b.DocEntry")
    Hope its help for you
    Give me reward points,
    Regards,
    G.Suresh.

  • Help for conditional formatting of a chart query!!!!!

    Dear Gurus,
    can Anyone give me a step by step for conditional formatting on the chart?
    I want my charts in my queries to be for example:
    green color when actual data <= version,
    Yellow if actual > version & 101%, red if actual >=101%.
    Thank You very much for sharing your Knowledge.

    Hi Des,
    You can achieve this through exceptional reporting. Choose your query & execute the report. click on the 'Exceptions & Conditions' button. create the exception you wish to have by choosing version & your key figure, in your case. when you click 'Transfer' it automatically gets activated & you can be able to view the colors set by you.
    Revert back for any modifications.
    Manoj

  • Query for calculating raw material requirements for the remaining quantities in sale order.

    Dear SAP Experts,
    Clients requirement :
                                         Client wish to know the quantities of raw materials needs to run the production order inorder to complete the remaining quantities in sale order.
    Need Clarification:
                                  I"m using the below query for this requirement. I wish to know whether this query suits for my clients requirement or not. If its so, I need to know how to group by T4.[Code] (Raw material Name)   and need to get the sum of    T4.[Quantity]  (BOM quantity)      and  (T1.[OpenQty]*T4.[Quantity]) as TOTALQTY under each raw material group
    SELECT T0.[DocNum], T0.[DocDate], T0.[CardCode],T0.[CardName], T1.[ItemCode], T1.[Dscription], T1.[Quantity] as salesorderQty , T1.[OpenQty], T2.onhand, T4.[Code] as Raw material Name,T4.[Quantity] as BOMQTY,  (T1.[OpenQty]*T4.[Quantity]) as TOTALQTY FROM ORDR T0  INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry] INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode] INNER JOIN OITT T3 ON T2.[ItemCode] = T3.[Code] INNER JOIN ITT1 T4 ON T3.[Code] = T4.[Father] WHERE  T0.[DocStatus] ='o' 

    You're posting in the Portuguese B1 space.
    You might want to post in the English one: SAP Business One Application

  • Query for formatted search

    Hi All,
    I have a line UDF called U_PO in the sales order documents that denotes our purchase order number that particular item is ordered on.
    I have another line UDF called U_XMill which I want to populate with the corresponding PO document due date.
    What would be my query for that?
    Basically, it should be something like:
    SELECT T0.DocDueDate FROM OPOR T0 WHERE T0.DocNum=$[$38.44.0] FOR BROWSE
    However, I am sure that "38.44" is wrong.
    It should denote my current document's UDF *.U_PO.
    And I am not sure what would be the correct notation for it.
    I was wondering if there was a help document I could refer to to figure out the corresponding field numbers for the cases like this.
    Thank you for your help.

    Hello
    use FMS on matrix (tables) as
    [ItemUID.ColumnUID.Type] or [TableName.FieldName]
    where itemUID is 38
    ColumnUID is U_XMill
    Type is 0 (general).
    There is a now-to guide on service.sap.com/smb/sbo where you can find how to us FMS.
    Regards
    J

  • How to write selection Query for the following requirment.

    Hi All,
    I am new to ABAP, I need a help ,
    I need to select all plants(WERKS) from MARC at Plant/Material level,
    then I need to take all sales organozation(VKORG) from T001w,
    then I need the company code(BUKRS) from TVKO based on VKORG,
    then I need the currency key(WAERS) from T001 based on BUKRS,
    Can any one help me in writing selection Query for the same?
    Thanks All,
    Debrup.

    Hi,
    Its easy for you if you learn SELECT with JOIN to complete your task. So SEARCH the forum with SELECT statement and you will get a lot of examples using which you can write your own.
    If you struck up anywhere revert back.
    Regards
    Karthik D

  • How to format better my query for a report?

    I have a shell script to run sql queries to get database information everyday.
    However here below, I want some columns to be indented to the right, and I also want to format the column with %.
    Also for the column name , underneath the column name, there are lines which very long and over one line, how to make it within a linesize?
    Checking DataGuard Status/Information
    message error time
    FACILITY SEVERITY DEST_ID number code CAL stamp MESSAGE
    ======================== ============= ========== ========== ========== === ========= ================================================================================================================================================================================================================================================================
    Thanks,

    Refer the below link for all format models and elements..etc
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm
    Hope this helps,
    Regards
    http://www.oracleracexpert.com
    Transportable tablespace export and import
    http://www.oracleracexpert.com/2009/09/transportable-tablespace-export-and.html
    Oracle data pump export/import with examples.
    http://www.oracleracexpert.com/2009/08/oracle-data-pump-exportimport.html

  • How to form a query for this requirment

    Hi Friends,
    I have a database table in which I store the employee data along with his phone number. Now this row of data can repeat for different phone number depending on if it is office phone or home phone or cell phone.
    But in the output of query, I need name of empoyee and other three columns namely "Home Phone", "Office Phone" and "Cell Phone".
    If employee has three rows for each kind of phone, then in the result of query all three columns for phone numbers should be filled, otherwise as many columns should be filled with data as different phone numbers employee has.
    Can any one please post SQL query for this scenario ?
    Thanks in Adavance

    I cannot imagine, that second and third query are
    under any circumstances faster as first one, but i
    can imagine that they are slower You stated that query without the inline view can only be faster. Did you check on optimizer plans or use tkprof to verify your claim?
    A quick check on those two selects
    SELECT object_id, object_type, object_name
      FROM user_objects;
    SELECT object_id, object_type, object_name
      FROM (SELECT object_id, object_type, object_name
              FROM user_objects)
              ;didn't show any changes in the explain plan unter 10g1.
    C.

  • Select Query for smart form-invoice

    Hi Folks,
    I have to fetch the following fields as per the requirement for desiging a invoice smartform.I had copied lb_bill_invoice smartform into z format.
    Can anyone here please give me the select query for the same.
    fields to fetched are as follows:-
    1.vbrp-arktx,
    2.vbrp-fkimg,
    3.konv-kbetr with respect to vbrk-knumv
    4.konv-kwert.
    And also what all I have to give in format interface and global definitions of the smartform.
    please help  me in this regard.
    Points will be given.
    K.Kiran.

    Hi,
    declare the variables V_arktx(40) and v_Qty like vbrp-fkimp  and other varaibles for Kbetr, kwert, knumv on the global definitions.
    select  single arktx fkimg into (v_arktx, v_qty) from vbrp
    where vbeln = LBBIL_IT_REFPURORD-BIL_NUMBER.
    select single knumv into v_knumv from vbrk where where vbeln = LBBIL_IT_REFPURORD-BIL_NUMBER.
    this select has to fire in the item level and in the loop.
    so have to write in the correct place.
    select kbetr kwert into (v_kbetr, v_kwert) from konv
    where where knumv = v_knumv and kposn = LBBIL_IT_REFPURORD-ITM_NUMBER.
    regards,
    anji

Maybe you are looking for