Convert one row to multiple column dynamic in smartform

i want to convert on row to multiple column in smartform.As number of column is not per define..Please suggest the way out in smartform

I saw a post and working perfect. The link is given below.
http://scn.sap.com/community/abap/blog/2013/10/06/the-case-of-dynamic-columns-in-smartform
Thanks to Eitan.

Similar Messages

  • Convert one row to multiple rows

    Hi
    i have a table Calendar_1 with 4 columns and 1 row
    CREATE TABLE Calendar_1
    Sunday CHAR(1),
    Monday CHAR(1),
    Tuesday CHAR(1),
    Wednesday CHAR(1)
    INSERT INTO Calendar_1 VALUES ('A', 'B', 'C', 'D');
    COMMIT;
    i need to get my output under a single column 'DAYS' as stated below
    DAYS
    A
    B
    C
    D
    Could you please provide me the required SQL
    REgards
    -Learnsequel

    Why not? There is only one row in the table... I think it's simplest way..Performance tuning mantra "Less I/O"
    Access the table once. I does not matter if its simple or complex. Keep the I/O Low.
    Check this out
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set autotrace traceonly explain
    SQL> set linesize 120
    SQL>
    SQL> select sunday from Calendar_1
      2  union all
      3  select monday from Calendar_1
      4  union all
      5  select tuesday from Calendar_1
      6  union all
      7  select wednesday from Calendar_1
      8  /
    Execution Plan
    Plan hash value: 105137738
    | Id  | Operation          | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |            |     4 |    12 |     8  (75)| 00:00:01 |
    |   1 |  UNION-ALL         |            |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| CALENDAR_1 |     1 |     3 |     2   (0)| 00:00:01 |
    |   3 |   TABLE ACCESS FULL| CALENDAR_1 |     1 |     3 |     2   (0)| 00:00:01 |
    |   4 |   TABLE ACCESS FULL| CALENDAR_1 |     1 |     3 |     2   (0)| 00:00:01 |
    |   5 |   TABLE ACCESS FULL| CALENDAR_1 |     1 |     3 |     2   (0)| 00:00:01 |
    Note
       - dynamic sampling used for this statement
    SQL> select decode(l, 1, sunday, 2, monday, 3, tuesday, 4, wednesday) days
      2    from Calendar_1                                                          
      3    cross join (select level l from dual connect by level <= 4)
      4  /
    Execution Plan
    Plan hash value: 2984077981
    | Id  | Operation                       | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |            |     1 |    25 |     4   (0)| 00:00:01 |
    |   1 |  MERGE JOIN CARTESIAN           |            |     1 |    25 |     4   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL             | CALENDAR_1 |     1 |    12 |     2   (0)| 00:00:01 |
    |   3 |   BUFFER SORT                   |            |     1 |    13 |     2   (0)| 00:00:01 |
    |   4 |    VIEW                         |            |     1 |    13 |     2   (0)| 00:00:01 |
    |*  5 |     CONNECT BY WITHOUT FILTERING|            |       |       |            |          |
    |   6 |      FAST DUAL                  |            |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       5 - filter(LEVEL<=4)
    Note
       - dynamic sampling used for this statement
    SQL> Look for the cost in the above plan. What you have done is wrong. Being simple does not make it correct.

  • One Row into multiple Column

    CREATE TABLE #ids (empid VARCHAR(200))
    INSERT INTO #ids SELECT '100,200,300,400'
    INSERT INTO #ids SELECT '1100,1200,1300,1400'
    I am trying to get output following format
    ID_1    ID_2   ID_3  ID_4
    100     200    300   400
    1000    1200   1300  1400
    Each row in EmpId column will have only max. four values
    Thanks
    V

    One more method:
    CREATE TABLE #ids (empid VARCHAR(200))
    INSERT INTO #ids SELECT '100,200,300,400'
    INSERT INTO #ids SELECT '1100,1200,1300,1400'
    select * from #ids
    ;WITH
    L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
    L1 AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
    L2 AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
    L3 AS(SELECT 1 AS c FROM L2 AS A, L2 AS B),
    Numbers AS(SELECT ROW_NUMBER() OVER(ORDER BY c) AS n FROM L3)
    SELECT [1] AS Column1, [2] AS Column2, [3] AS Column3, [4] AS Column4
    FROM
    (SELECT rn,
    ROW_NUMBER() OVER (PARTITION by rn ORDER BY nums.n) AS PositionInList,
    LTRIM(RTRIM(SUBSTRING(valueTable.empid, nums.n,
    charindex(N',', valueTable.empid + N',', nums.n) - nums.n))) AS [Value]
    FROM Numbers AS nums INNER JOIN (Select row_number()over (Order by (Select NULL)) rn , Empid From #ids) AS valueTable ON nums.n <= CONVERT(int, LEN(valueTable.empid))
    AND SUBSTRING(N',' + valueTable.empid, n, 1) = N',') AS SourceTable
    PIVOT
    MAX([VALUE]) FOR PositionInList IN ([1], [2], [3], [4])
    ) AS Table2
    drop table #ids

  • Convert multiple rows to one row with multiple columns

    Hi
    i have a table Match_1 with 2 columns 'Source' and 'target'.One source can have multiple targets and that number could be anything
    CREATE TABLE Match_1
    Source CHAR(1),
    Target CHAR(1)
    INSERT INTO Match_1 VALUES ('A', 'B');
    INSERT INTO Match_1 VALUES ('A', 'C');
    INSERT INTO Match_1 VALUES ('A', 'D');
    INSERT INTO Match_1 VALUES ('A', 'E');
    INSERT INTO Match_1 VALUES ('V', 'X');
    INSERT INTO Match_1 VALUES ('V', 'Y');
    INSERT INTO Match_1 VALUES ('V', 'X');
    INSERT INTO Match_1 VALUES ('V', 'W');
    COMMIT;
    i need to get my output in the below format
    Source     target 1     target 2     target 3     target 4          target n
    A     B          C          D               
    V     X          Y          Z          W          
    Could you please provide me the required SQL.
    REgards
    -Learnsequel

    What is your database version (4 digit) ? also my example won't be generate columns for your information:
    it will produce a result like that :
    select source, listagg(target,',') within group (order by target)
      from  match_1
      group by source;
    A     B,C,D,E
    V     W,X,X,Yps: in previos post, I wrote "with" word wrong in sql.

  • Split one row into multiple columns

    Hi,
    Data in one CLOB column in a table storing with delimiter, ##~~##. Ex. ##~~##abc##~~##defgh##~~##ijklm##~~##nopqr (data starts with delimiter). Please help me to split the data into multiple rows like below and it should be in the same order.
    abc
    defgh
    ijklm
    nopqr
    I am using Oracle 11g.
    Thanks.

    Thanks Hoek for your response. Before posting my question in the forum, I tried similar query. It is working with one character as delimiter.
    with test as (select 'ABC,DEF,GHI,JKL,MNO' str from dual )
    select regexp_substr (str, '[^,]+', 1, rownum) split
    from test
    connect by level <= length (regexp_replace (str, '[^,]+')) + 1;
    Above query is giving correct result by fetching 5 rows. I have modified the query like below...
    with test as (select 'ABC,,,DEF,,,GHI,,,JKL,,,MNO' str from dual )
    select regexp_substr (str, '[^,,,]+', 1, rownum) split
    from test
    connect by level <= length (regexp_replace (str, '[^,,,]+')) + 1;
    Above query resulting 13 rows and last 8 rows are nulls. Number of null rows are increasing, if I increase number of characters in delimiter. Could you please tell me how to avoid those null rows.
    Thanks.

  • Multipe rows to Multiple Columns - Oracle9i

    Hi
    I know there have been similar threads however I haven't found a suitable solution from them.
    I'm using Oracle 9i and trying to convert multiple rows to multiple columns.
    CREATE TABLE TEST_VALUES
    CUSTOMER_ID NUMBER(10),
    VAL VARCHAR2(100)
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(10,'VAL1');
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(10,'VAL2');
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(20,'VAL1');
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(30,'VAL3');
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(30,'VAL4');
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(40,'VAL5');
    INSERT INTO TEST_VALUES(CUSTOMER_ID,VAL)VALUES(40,'VAL6');
    COMMIT;
    SELECT * FROM TEST_VALUES
    CUSTOMER_ID     VAL
    10     VAL1
    10     VAL2
    20     VAL1
    30     VAL3
    30     VAL4
    40     VAL5
    40     VAL6
    I want one row per CUSTOMER_ID with two columns to store the values
    CUSTOMER_ID FIRST_VAL SECOND_VAL
    10 VAL1 VAL2
    20 VAL1 NULL
    30 VAL3 VAL4
    40 VAL5 VAL6
    There are only 6 possible 'VAL' values however there are a large number of CUSTOMER_id values. I tried DECODE as suggested elsewhere but that creates 6 columns. However I only want two output columns as there are no more than two values per customer.
    If I had 11g I would try pivot, can anyone please suggest any solutions?
    Many Thanks
    GB

    Thanks Bhushan, that was nearly what I was after. For CUSTOMER 20 it gave
    20 VAL1 VAL1
    so to make it
    20 VAL1 NULL
    I just changed your query slightly to
    select distinct
    customer_id,
    min(val) over (partition by (customer_id)) val1,
    CASE WHEN max(val) over (partition by (customer_id)) = min(val) over (partition by (customer_id)) THEN NULL
    ELSE max(val) over (partition by (customer_id)) END val2
    from test_values
    order by customer_id
    and that gives the correct results. Just checking the full data set now.
    Thanks for your help.

  • Converting each row in a column to an XML

    Hi everyone,
    Using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
    I have a table where there is a comments column which is VARCHAR2. That column contains string data in the form of XML tags.
    Like for eg. *<tag_name attr_name="10"/>* (sorry cant provide the exact values as I'm not allowed to)
    There are many such rows. Now I want to use these strings and operate on them as XML like using XPath to find certain attributes etc.
    I tried using the extract function and to use it i need a XMLType object. So I tried to create one using the XMLType() constructor.
    But it gives me the error ORA-19032: Expected XML tag , got no content
    When I looked it up on the net, I found that this error number doesn't correspond to the error message that I'm getting. The error msg found on the internet was Expected XML tag string got string
    I used this query
    SELECT XMLType (<column>) FROM <table>;But when I modified it (based on someone's hunch) to
    SELECT XMLType (<column>)
      FROM <table>
    WHERE ROWNUM <= 1;The query worked fine. Like it can take only one row.
    I also tried like this
    SELECT XMLType ('<tag_name attr_name="10"/>')
      FROM DUAL;This too worked fine.
    So finally this has left me completely confused. Is there a way to convert every row in a column to an XMLType object so that I can use the extract function to gather information about it.
    For the time being I have used REGEXes to write the code. But having the flexibility of xml would be better.
    Any help would be appreciated.
    Regards,
    Arijit
    Edited by: Arijit Kanrar on May 23, 2013 5:27 AM

    Arijit,
    The error message is correct. What you found is merely the generic message with string placeholders.
    The error message is also pretty self-explanatory : you can't pass an empty string (NULL) to the XMLType constructor.
    SQL> select xmltype('') from dual;
    ERROR:
    ORA-19032: Expected XML tag , got no content
    ORA-06512: at "SYS.XMLTYPE", line 310
    ORA-06512: at line 1
    no rows selectedYou have to either add a WHERE clause to filter out NULL columns, or use a CASE statement to only convert strings that aren't empty :
    SELECT XMLType (<column>)
      FROM <table>
    WHERE <column> IS NOT NULL ;
    SELECT CASE WHEN <column> IS NOT NULL THEN XMLType (<column>) END
    FROM ...And do not use EXTRACT if you want to access scalar values, use EXTRACTVALUE instead :
    SQL> select extractvalue(xmltype('<tag_name attr_name="10"/>'), '/tag_name/@attr_name') from dual;
    EXTRACTVALUE(XMLTYPE('<TAG_NAMEATTR_NAME="10"/>'),'/TAG_NAME/@ATTR_NAME')
    10

  • Find MIN, MAX of multiple rows from multiple columns

    Hello,
    I need to figure out how to pull the MIN/MAX of multiple rows from multiple columns into one column. Even if some are NULL/blank.
    For Example: (C: Column, R: Row, N - NULL/Blank)
    C:____1____2____3____ 4____Max
    R:____20___22___13____4____*22*
    R:____N____N____32____14___*32*
    R:____N____12____N____N____*12*
    That is, it always gives a value for MIN/MAX unless there are NO values in all the rows of the columns.
    So if there is one value, it will select that for the MIN/MAX, as it's the smallest/biggest since there is nothing to compare it to.
    Here is my current code:
    CASE WHEN COLUMN 1 < COLUMN 2 THEN COLUMN 2 ELSE COLUMN 1 END

    Hi Thank you for your feedback, unfortunately, I just found out that EVALUATE Function is disabled in our environment for security reasons, so the only other way I've discovered is this:
    The problem is that none of the conditions in the case statement are met--so the column is set to null. You can add a WHEN statement (section 2 below) to catch the nulls. There are five cases to consider:
    Case 1: begin insp > bad order
    Case 2: begin insp < bad order
    Case 3: bad order only (begin insp is NULL)
    Case 4: begin insp only (bad order is NULL)
    Case 5: both begin insp is NULL and bad order is NULL
    1) If bgn-crm-insp-ob > report-bo-ob then bgn-crm-insp-ob
    (Case 1)
    CASE WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob') > filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    2) If report-bo-ob is NULL then bgn-crm-insp-ob
    (Case 4, 5) for case 5, you will get NULL
    WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') IS NULL THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    3) Else report-bo-ob
    (Cases 2, 3)
    ELSE filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') END
    Hopefully this works, I'll give feedback if it does, or if you have any further suggestions please submit, again, THANK YOU SO MUCH ANYWAYS!

  • Merge multiple rows into single row (but multiple columns)

    How to merge multiple rows into single row (but multiple columns) efficiently.
    For example
    IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
    23 asdc 1 Location USA NM ABQ Four Seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    65 affc 2 Location USA TX AUS Hilton 92305
    65 affc 2 Stats 5510 42.7 46 9999
    65 affc 2 Audit 1996 July 172 1100
    where different attributes mean different thing for each Information_type.
    For example for Information_Type=Location
    Attribute_1 means Country
    Attribute_2 means State and so on.
    For example for Information_Type=Stats
    Attribute_1 means Population
    Attribute_2 means American Ethnicity percentage and so on.
    I want to create a view that shows like below:
    IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
    23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
    65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
    Thanks

    Hi,
    That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
    I hope this answers your question.
    If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Is there a way to convert 8 Rows by 2 Columns to 2 Rows by 8 Columns?

    I have tried but came to an stop...
    How do I convert 8 Rows by 2 Columns to 2 Rows by 8 Columns?
    as shown in the vi attached
    Thank you very much...
    Solved!
    Go to Solution.
    Attachments:
    Eight Rows Two Col convert to two Rows Eight Col.vi ‏8 KB

    JohnMc19 wrote:
    Hi Diego2000,
    Trying using the Transpose 2D array function found in the Array functions palette, think it is what you are asking for.
    Regards,
    No, for the required transformation reshape array is required, not transpose.
    Compare:
    Andrey.

  • Display only one row for distinct columns and with multiple rows their valu

    Hi,
    I have a table having some similar rows for some columns and multiple different rows for some other columns
    i.e
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    9825000111 01-jan-06 'a' 991543154 02-feb-06 d
    9825000111 01-jan-06 'a' 154845545 10-mar-06 a
    What i want is to display only one row for above distinct row along with multiple non distinct colums
    ie
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    991543154 02-feb-06 d
    154845545 10-mar-06 a
    regards,
    Kumar

    Re: SQL Help

  • How to get multiple records in one row and different column

    Hi All,
    I am using oracle database 11g
    and i have a two tables table_1, table_2
    table_1 having columns
    emp_no
    first_name
    middle_name
    last_name
    email
    and table_2 having columns
    emp_no
    phone_type
    phone_number
    and having entires
    emp_no phone_type phone_number
    1001 MOB 9451421452
    1001 WEMG 235153654
    1001 EMG 652341536
    1002 MOB 9987526312
    1003 WEMG 5332621456
    1004 EMG 59612356
    Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
    emp_no first_name middle_name last_name email mobile officeno
    1001 mark null k [email protected] 9451421452 235153654
    1002 john cena gary [email protected] 9987526312 null
    1003 dany null craig [email protected] null 5332621456
    1004 donald finn sian [email protected] null null
    can i have any inputs to achive this???
    Regards
    $sid

    Frank Kulash wrote:
    sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
    SELECT     *
    FROM     table_1      t1
    JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    PIVOT     (    max(t2.phone_number)
         FOR  t2.phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
            FOR  t2.phone_type  IN  ( 'MOB'   AS mob
    ERROR at line 19:
    ORA-01748: only simple column names allowed hereYou need to:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
         table_3 as (
                     select  t1.emp_no,first_name,middle_name,last_name,email,
                             phone_type,phone_number
                       FROM     table_1      t1
                       LEFT JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    SELECT     *
    FROM     table_3
    PIVOT     (    max(phone_number)
         FOR  phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
        EMP_NO FIRST_ MIDD LAST_ EMAIL                     MOB       WEMG
          1004 donald finn sian  [email protected]
          1003 dany        craig [email protected] null            5332621456
          1001 mark        k     [email protected]      9451421452  235153654
          1002 john   cena gary  [email protected]    9987526312
    SQL>SY.

  • Master-detail: one detail row with multiple columns

    Hi All,
    I have a normal master-detail situation in the databse, in the form however all detail rows should be displayed in one single row, using more columns. The number of details are limited, so I can use a predefined number of text-items.
    Any ideas on how to implement this?
    Regards,
    Michiel

    create a function that returns your details. e.g. :
    function get_detail (P_PK, P_rownum) ...
    let's use the example dept and emp. Your master is dept. Your detail is emp. deptno is the PK for the master table.
    you have in your form multi-records of dept and maybe 5 items for employees. The name of the text-items TI_data_1 .. TI_data_5. In the post-query-trigger you code :
    :DEPT.TI_data_1 := get_detail (:DEPT.DEPTNO, 1);
    :DEPT.TI_data_2 := get_detail (:DEPT.DEPTNO, 2);
    if you need more columns create a loop and use the built-in COPY for assigning the detail-values to the text-items.
    the get_detail e.g. is a select-statement:
    SELECT ENAME
    FROM EMP
    WHERE DEPTNO = P_PK
    AND rownum = P_rownum
    ORDER BY EMPNO
    try it
    Gerd

  • Multiple rows to multiple columns on one row using SQL

    Hi
    I am attempting to select back multiple values for a specific key on one row. See the example below. I have been able to use the sys_connect_by_path to combine the fields into one field but I am unable to assign them to fields of their own. See the example below
    TABLE DETAILS:
    Policy id plan name
    111 A Plan
    111 B Plan
    111 Z Plan
    112 A Plan
    112 Z Plan
    My desired result is to be able to show the output as follows
    Policy ID Plan_1 Plan_2 Plan_3
    111 A Plan B Plan Z PLan
    112 A Plan Z PLan
    Can you help???

    Thanks for all the replies. Perhaps I could give a little more detail incldung a sample table and insert statements. The repsonses work fine but the problem I was having was that I did not want to have to hardcode in the plan_name to a decode statement. The list of plans is not exhaustive. There could be numerous different plans in the table. I have amended the details below slightly to try and give a little more information as I was probably not too clear at the start. Would you know if there is a way to do this without hardcoding the plan values in?
    Thanks in advance!
    CREATE TABLE TEST_SAMPLE (
    POLICY_NUMBER VARCHAR2(10),
    plan_name varchar2(20) );
    INSERT INTO TEST_SAMPLE VALUES ('111', 'A Plan');
    INSERT INTO TEST_SAMPLE VALUES ('111', 'B Plan');
    INSERT INTO TEST_SAMPLE VALUES ('111', 'C Plan');
    INSERT INTO TEST_SAMPLE VALUES ('112', 'J Plan');
    INSERT INTO TEST_SAMPLE VALUES ('112', 'Z Plan');
    My desired result is to be able to show the output as follows
    Policy ID Plan_1 Plan_2 Plan_3
    111 A Plan B Plan C PLan
    112 J Plan Z PLan

  • How to filter rows where multiple columns meet criteria, ignoring rows where only some columns meet criteria

    Hi All,
    Question: How do I filter rows out of a query where multiple columns are equal to a single question mark character?
    Background: I'm using SQL 2008 R2.  Furthermore, the part of my brain that helps me create less-than-simple queries hasn't been working for the last 4 days, apparently, and now I need help.
    We have about 4,000 rows in a table.  This data set was generated from an exported report, and many of the rows in the detail table were not actual data rows but were simply "header" rows.  For those table rows, most of the columns have
    a single question mark as the value.
    Some of the detail rows have one or more question mark values, too, so it's important that these rows don't get filtered out.
    When I include criteria like "WHERE col1 <> '?' AND col2 <> '?' AND col3 <> '?' AND col4 <> '?'", all rows with a question mark value for even a single one of those columns get filtered out.  How do I filter out rows
    where all columns 1-4 contain a question mark value?
    Thanks for your help,
    Eric

    I just tried to create to create a scenario for you. Please see ig you're looking for something like this.
    Create table test_Question_mark
    RecordID INT identity(1,1),
    Col1 varchar(10),
    Col2 varchar(10),
    Col3 varchar(10),
    Col4 varchar(10),
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','?','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','??','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','??','??','??')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ??','??','??')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ?','??','??')
    --drop table test_Questio_mark
    select * from test_Question_mark
    select * from test_Question_mark 
    WHERE 
    (CHARINDEX('?', Col1,1) > 0 AND CHARINDEX('?', Col1, CHARINDEX('?', Col1,1)+1) = 0) AND 
    (CHARINDEX('?', Col2) > 0 AND CHARINDEX('?', Col2, CHARINDEX('?', Col2,1)+1) = 0) AND 
    (CHARINDEX('?', Col3,1) > 0 AND CHARINDEX('?', Col3, CHARINDEX('?', Col3,1)+1) = 0) AND 
    (CHARINDEX('?', Col4,1) > 0 AND CHARINDEX('?', Col4, CHARINDEX('?', Col4,1)+1) = 0) 
    --drop table test_Questio_mark
    I hope above solution will help.
    Thanks!
    Ashish.

Maybe you are looking for

  • Two iPhones with one email account, notes and alerts from separate users show up on each others phones

    My husband and I have always shared a personal email account. We got iPhones a year ago and each set them up to view our shared email. He also has a separate email account for work. Unfortunately, when either of us takes a "note" on the notepad or se

  • How can I export comments and tracked changes from Pages to Word?

    I just purchased Pages and tried to export a couple pages of my document to Microsoft Word so I could send them for review to a client who does not have Pages; however, when I copy-pasted into Word, none of the comments or tracked changes showed up i

  • Problems installing CS6

    I recently had to uninstall and re-install my CS6 software on my laptop due to InDesign and Illustrator not opening even when started in safe mode. Most of the applications were unable to be installed again due to an error code, reading" OS requireme

  • Relation between activity , opportunity and lead

    Hello Could you please tell me relationship between activity, opportunity and lead? How I can create opportunity based on activity? I didnt find where its possible Thanks

  • Enhancement Spots

    Hi, Can any one tell me about enhancement spots? What is the difference between the classic BAdI Builder and the new one?