Get datetime in 1st row of another column

Hi Everyone,
Please anyone help me...
Below is the query and output.
Query:
SELECT
  WMUMF.BIZDOCTYPEDEF.TYPENAME,
  Table__52.BD_PARTNERORDERNUMBER,
  Table__67.BD_TRACKINGNUMBER,
  WMUMF.BIZDOCATTRIBUTE.STRINGVALUE,
  TO_DATE(TO_CHAR(WMUMF.BIZDOC.DOCTIMESTAMP,'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY HH24:MI:SS')
FROM
  WMUMF.PARTNER  SENDER,
  WMUMF.PARTNER  RECEIVER,
  WMUMF.BIZDOCTYPEDEF,
  WMUMF.BIZDOC,
  SELECT
      WMUMF.BIZDOCARRAYATTRIBUTE.DOCID,
      WMUMF.BIZDOCARRAYATTRIBUTE.STRINGVALUE BD_PartnerOrderNumber
      FROM
      WMUMF.BIZDOCATTRIBUTEDEF  BIZDOCATTRIBUTEDEF_A1,
      WMUMF.BIZDOCARRAYATTRIBUTE
      WHERE
      WMUMF.BIZDOCARRAYATTRIBUTE.ATTRIBUTEID=BIZDOCATTRIBUTEDEF_A1.ATTRIBUTEID AND
      Bizdocattributedef_A1.Attributename  In  ( 'BD_PartnerOrderNumber'  )
  )  Table__52,
  SELECT
WMUMF.BIZDOCARRAYATTRIBUTE.DOCID,
WMUMF.BIZDOCARRAYATTRIBUTE.STRINGVALUE BD_TrackingNumber
FROM
WMUMF.BIZDOCATTRIBUTEDEF BIZDOCATTRIBUTEDEF_A1,
WMUMF.BIZDOCARRAYATTRIBUTE
WHERE
WMUMF.BIZDOCARRAYATTRIBUTE.ATTRIBUTEID=BIZDOCATTRIBUTEDEF_A1.ATTRIBUTEID AND
Bizdocattributedef_A1.Attributename In ( 'BD_TrackingNumber' )
  )  Table__67,
  WMUMF.BIZDOCATTRIBUTEDEF,
  SELECT
      WMUMF.BIZDOCARRAYATTRIBUTE.DOCID,
      WMUMF.BIZDOCARRAYATTRIBUTE.STRINGVALUE BD_SiteID
      FROM
      WMUMF.BIZDOCATTRIBUTEDEF  BIZDOCATTRIBUTEDEF_A1,
      WMUMF.BIZDOCARRAYATTRIBUTE
      WHERE
      WMUMF.BIZDOCARRAYATTRIBUTE.ATTRIBUTEID=BIZDOCATTRIBUTEDEF_A1.ATTRIBUTEID AND
      Bizdocattributedef_A1.Attributename  In  ( 'BD_SiteID'  )
  )  Table__44
WHERE
  ( WMUMF.BIZDOC.DOCTYPEID=WMUMF.BIZDOCTYPEDEF.TYPEID  )
  AND  ( WMUMF.BIZDOC.RECEIVERID=RECEIVER.PARTNERID  )
  AND  ( SENDER.PARTNERID=WMUMF.BIZDOC.SENDERID  )
  AND  ( WMUMF.BIZDOC.DOCID=WMUMF.BIZDOCATTRIBUTE.DOCID  )
  AND  ( WMUMF.BIZDOCATTRIBUTEDEF.ATTRIBUTEID=WMUMF.BIZDOCATTRIBUTE.ATTRIBUTEID  )
  AND  ( Table__44.DOCID(+)=WMUMF.BIZDOC.DOCID  )
  AND  ( WMUMF.BIZDOC.DOCID=Table__46.DOCID(+)  )
  AND  ( WMUMF.BIZDOC.DOCID=Table__52.DOCID(+)  )
  AND  ( WMUMF.BIZDOC.DOCID=Table__67.DOCID(+)  )
  AND
   WMUMF.BIZDOCTYPEDEF.TYPENAME  IN  ( 'doc_Xml_HoldReleaseNotification_CustomXML_Cisco','doc_Xml_PIP_3A9CancellationRequest_V_11_01'  )
   AND
   SENDER.CORPORATIONNAME  =  'CISCO LSS (E2Open)'
   AND
   RECEIVER.CORPORATIONNAME  =  'FLEXTRONICS'
   AND
   WMUMF.BIZDOCATTRIBUTEDEF.ATTRIBUTENAME  =  'ApplicationMessageType'
   AND
   WMUMF.BIZDOCATTRIBUTE.STRINGVALUE  IN  ( 'H','R','3A9V11.01.00'  )
   AND
   Table__44.BD_SITEID  =  '027'
  AND
   WMUMF.BIZDOC.DOCTIMESTAMP >= TO_DATE('06/15/2013','MM/DD/YYYY')
   AND WMUMF.BIZDOC.DOCTIMESTAMP <= SYSDATE+1
Output:
PartnerOrderNumber
DateTime
StringValue
Tracking Number
Document
PO1
1 am
H
123
DOC
PO1
2 am
H
246
DOC
PO1
3 am
R
125
DOC
PO1
4 am
H
678
DOC
PO2
5 am
H
890
DOC
PO2
6 am
R
098
DOC
PO2
7 am
H
001
DOC
PO2
8 am
R
870
DOC
PO3
9 am
H
008
DOC
PO3
10 am
H
065
DOC
PO3
11 am
R
593
DOC
PO3
12 pm
H
636
DOC
PO3
1 pm
H
978
DOC
PO3
2 pm
R
675
DOC
But I need like below...
PartnerOrderNumber
H DateTime
R DateTime
Tracking Number
Document
PO1
1 am
3 am
123
DOC
PO1
2 am
246
DOC
PO2
4 am
6 am
678
DOC
PO2
5 am
890
DOC
PO2
7 am
8 am
001
DOC
PO3
9 am
11 am
008
DOC
PO3
10 am
065
DOC
PO3
12 pm
2 pm
636
DOC
PO3
1 pm
978
DOC
My aim is to get H datetime in one column and R datetime in another column but only in 1st row of H datetime. PO3 has H H R H H R so each R datetime should be in 1st of H datetime.
Thanks in Advance,
Sindhu

This forum is for the SQL Developer tool, not for general SQL or PL/SQL questions.  The clue is in the name. 
Try asking in the Database General or SQL and PL/SQL forums.

Similar Messages

  • Adding Specific columns of dynamic internal table row into another column

    Hi Gurus,
    I need to add  few columns of a dynamic internal table row into another column:
    Article description hy01 hy02 total
    101      panza         10     12      22
    102      masht         12     12     24
    dynamic internal table is created and columns hy01 hy02.... can increase
    How to add the the values in hy01 hy 02... into total.
    Regards,
    Dep

    Hi,
    If you really want to have a dynamic table, then you will have to find a way to generate a whole new table, and then copy the data from the old table to the new one. There is no way to modify a type during runtime in ABAP.
    Here an example how to generate a dynamic table based on another internal table, hope this will help you.
    TYPE-POOLS: slis.
    PARAMETERS: p_nb_hy TYPE i DEFAULT 2. "Number of new HY columns to be added
    * Type ZST_T:
    *   matnr  TYPE matnr
    *   maktx  TYPE maktx
    *   hy01   TYPE i
    *   total  TYPE i
    TYPES: ty_t TYPE STANDARD TABLE OF zst_s.
    PERFORM main.
    *&      Form  main
    *       text
    FORM main.
      DATA: lt_fieldcat     TYPE slis_t_fieldcat_alv,
            lt_t            TYPE ty_t,
            lr_new_t        TYPE REF TO data.
      FIELD-SYMBOLS: <lt_new_t> TYPE STANDARD TABLE.
      "Add some lines to LT_T just to have something to display on screen
      DO 10 TIMES.
        APPEND INITIAL LINE TO lt_t.
      ENDDO.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'ZST_S'
        CHANGING
          ct_fieldcat      = lt_fieldcat.
      "Copy LT_T to LR_NEW_T
      PERFORM extend_and_copy_table USING lt_t p_nb_hy CHANGING lr_new_t lt_fieldcat.
      CLEAR lt_t. "Not needed anymore...
      ASSIGN lr_new_t->* TO <lt_new_t>.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = lt_fieldcat
        TABLES
          t_outtab    = <lt_new_t>.
    ENDFORM.                    "main
    *&      Form  extend_and_copy_table
    FORM extend_and_copy_table USING ut_t           TYPE STANDARD TABLE
                                     uv_nb_hy       TYPE i
                               CHANGING cr_t        TYPE REF TO data
                                        ct_fieldcat TYPE slis_t_fieldcat_alv
                               RAISING cx_sy_struct_creation cx_sy_table_creation.
      DATA: lo_tabledescr      TYPE REF TO cl_abap_tabledescr,
            lo_structdescr     TYPE REF TO cl_abap_structdescr,
            lo_new_structdescr TYPE REF TO cl_abap_structdescr,
            lo_new_tabledescr  TYPE REF TO cl_abap_tabledescr,
            lt_components      TYPE cl_abap_structdescr=>component_table,
            ls_component       TYPE cl_abap_structdescr=>component,
            lv_field_cnt       TYPE numc2,
            ls_fieldcat        TYPE slis_fieldcat_alv,
            lr_fieldcat        TYPE REF TO slis_fieldcat_alv.
      FIELD-SYMBOLS: <ls_old_s> TYPE ANY,
                     <lt_new_t> TYPE STANDARD TABLE,
                     <ls_new_s> TYPE ANY.
      "Get the list of all components from UT_T line structure
      lo_tabledescr  ?= cl_abap_tabledescr=>describe_by_data( ut_t ).
      lo_structdescr ?= lo_tabledescr->get_table_line_type( ).
      lt_components  = lo_structdescr->get_components( ).
      "The new columns will be from type of column HY01
      ls_component-type = lo_structdescr->get_component_type( 'HY01' ).
      "The new columns will have the same fieldcat info as column HY01
      READ TABLE ct_fieldcat INTO ls_fieldcat WITH KEY fieldname = 'HY01'.
      "HY<lv_field_cnt> = new field name
      lv_field_cnt = uv_nb_hy + 1.
      "For each new column...
      DO uv_nb_hy TIMES.
        "Generate the new column field name
        CONCATENATE  'HY' lv_field_cnt INTO ls_component-name.
        ls_fieldcat-fieldname = ls_component-name.
        "Add the new field to the components of the new structure
        INSERT ls_component INTO lt_components INDEX 4.
        "Add the new field's fieldcat info to the fieldcat
        INSERT ls_fieldcat  INTO ct_fieldcat   INDEX 4.
        lv_field_cnt = lv_field_cnt - 1.
      ENDDO.
      "Adjust the COL_POS from fieldcat
      LOOP AT ct_fieldcat REFERENCE INTO lr_fieldcat.
        lr_fieldcat->col_pos = sy-tabix.
      ENDLOOP.
      "Create the new table
      lo_new_structdescr = cl_abap_structdescr=>create( p_components = lt_components ).
      lo_new_tabledescr  = cl_abap_tabledescr=>create( p_line_type = lo_new_structdescr ).
      CREATE DATA cr_t TYPE HANDLE lo_new_tabledescr.
      ASSIGN cr_t->* TO <lt_new_t>.
      "Copy all data from old to new table
      LOOP AT ut_t ASSIGNING <ls_old_s>.
        APPEND INITIAL LINE TO <lt_new_t> ASSIGNING <ls_new_s>.
        MOVE-CORRESPONDING <ls_old_s> TO <ls_new_s>.
      ENDLOOP.
    ENDFORM.                    "main

  • How to get difference between two rows for a column field?

    hi, all,
    Could anyone show me what query statement is to get the difference betweem two rows for two column fields?
    The tables and its records are like this:
    id,      begin,      end
    p1         21          30
    p2          45          60
    p3          120          150
    I would like to have the query result like this
    id,    diff
    p1     15    --- which is 45 minus 30
    p2     60    --- which is 120 minus 60
    and so on...
    thank you in advance.
    Raffy

    You can use the LAG function to access values from previous rows:
    with q as (select 'p1' id, 21 v_start, 30 v_end from dual
    union all
    select 'p2', 45, 60 from dual
    union all
    select 'p3', 120, 150 from dual)
    select id, v_start, v_end, v_start - lag (v_end, 1, 0)
      over (order by id) v_diff from q
    ID,V_START,V_END,V_DIFF
    p1,21,30,21
    p2,45,60,15
    p3,120,150,60
    See the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions075.htm

  • Search one column for value in another column

    Hello,
    I am trying to take the whole value from one column, and see if that string appears anywhere in another colmn. So if one row in one column has the value "cat", I want to see if that string appears anywhere in any row in another column: so a row with the value "The cat sat on the mat" would return true.
    I have tried:
    select term from pic_lib_keywords, csv
    where contains (csv.nhm_field_asset_description,pic_lib_keywords.term) >0;
    But I get the error:
    ORA-20000: Oracle Text error:
    DRG-50901: text query parser syntax error on line 1, column 32
    20000. 00000 - "%s"
    *Cause:    The stored procedure 'raise_application_error'
    was called which causes this error to be generated.
    *Action:   Correct the problem as described in the error message or contact
    the application administrator or DBA for more information.
    Can you use 2 columns in this way, or does the search term have to be a literal? Any suggestions would be appreciated.
    Thank you.

    It works for me, as shown below.
    SCOTT@orcl_11gR2> select * from v$version
      2  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    5 rows selected.
    SCOTT@orcl_11gR2> create table csv
      2    (nhm_field_asset_description  clob)
      3  /
    Table created.
    SCOTT@orcl_11gR2> insert all
      2  into csv values ('The cat sat on the mat.')
      3  into csv values ('The dog sat on the mat.')
      4  select * from dual
      5  /
    2 rows created.
    SCOTT@orcl_11gR2> create table pic_lib_keywords
      2    (term  varchar2(30))
      3  /
    Table created.
    SCOTT@orcl_11gR2> insert all
      2  into pic_lib_keywords values ('cat')
      3  into pic_lib_keywords values ('mouse')
      4  select * from dual
      5  /
    2 rows created.
    SCOTT@orcl_11gR2> create index test_idx
      2  on csv (nhm_field_asset_description)
      3  indextype is ctxsys.context
      4  /
    Index created.
    SCOTT@orcl_11gR2> select term
      2  from   pic_lib_keywords, csv
      3  where  contains
      4             (csv.nhm_field_asset_description,
      5              pic_lib_keywords.term) >0
      6  /
    TERM
    cat
    1 row selected.
    SCOTT@orcl_11gR2>

  • How do I get the layout guides (A,B,C column headers and 1,2,3 Row Headers) to print with my spreadsheet?

    How do I get the Layout Guides (A,B,C column headers and 1,2,3 Row Headers) to print on my spreadsheet? They are invaluable for discussing the data with my clients over the phone.
    They appear while I am editing, but don't print with the spreadsheet. I know how to do it in Excel, but I am transitioning to Numbers. I can't imagine I have to type them into their own columns and rows. It must be a difference in vernacular that I can't find the solution in the User Guide. Can anyone help?

    Hi ktjobauer,
    Numbers is not Excel and Excel is not Numbers. Numbers is WYSIWYG (at least in File > Print and the actual printout).
    I can't imagine I have to type them into their own columns and rows.
    No, you don't. You can use the charm of Numbers to create cell references for your Excel clients.
    In this Numbers Table, I have added some extra Columns that you can hide later.
    Column B =COLUMN(A2)
    Column C =HLOOKUP(B2,'Table 1-1' :: $1:$2,2,FALSE)      [explanation later]
    Column D =ROW(B2)
    Column E =C2&D2
    Add those formulas to the first Body Row (below the Header Row) and Fill Down.
    Column C refers to another Table which you need only create once, to convert a Column number to a letter:
    and so on from 1-26, A-Z.
    You can move the second Table to another Sheet to hide it. Formulas will automatically adjust to keep the links between Sheets.
    Now in the first Table, select and Hide Columns B,C,D. Formulas will continue to work with hidden cells:
    Regards,
    Ian.

  • Radio group in classic report based on another column on the same row.

    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    Application Express 4.1.0.00.32
    How can I have a radio group column based on an LOV utilizing another column on the same row of the report?
    For example: what if I had a survey application and depending on the likert scale that was assigned to the question there would be different possible answer choices:
    Question 1 on row 1 of the report: The class instructor was friendly?
    Likert scale choice is Agreement.
    Choices on Radio Group: Strongly Agree, Agree, Undecided, Strongly Disagree
    Question 2 on row 2 of the report: The class offered good materials?
    Likert scale choice is Quality.
    Choices on Radio Group: Excellent, Below Average, Average, Above Average, Excellent
    The radio group can change per row depending on the Likert scale assigned to the question which is assigned to a different column on the row.
    Can LOV utilize the column? :
    SELECT scale_text
    FROM scale_choices
    WHERE scale_category_choice_id = 2 <<= this would be the Likert scale identifier
    ORDER
    BY display_order

    Here is the answer:
    APEX_ITEM.SELECT_LIST_FROM_QUERY(
    p_idx IN NUMBER,
    p_value IN VARCHAR2 DEFAULT NULL,
    p_query IN VARCHAR2,
    p_attributes IN VARCHAR2 DEFAULT NULL,
    p_show_null IN VARCHAR2 DEFAULT 'YES',
    p_null_value IN VARCHAR2 DEFAULT '%NULL%',
    p_null_text IN VARCHAR2 DEFAULT '%',
    p_item_id IN VARCHAR2 DEFAULT NULL,
    p_item_label IN VARCHAR2 DEFAULT NULL,
    p_show_extra IN VARCHAR2 DEFAULT 'YES')
    RETURN VARCHAR2;

  • How to get fourthly row (row4) first column value (col1) in matrix

    Hi to all,
    In FMS, how to get fourthly row (row4) first column value (col1) in matrix in document.
    select $[$38.1.4]
    But it display the first row
    Please give me hint.
    Thank you

    Hi Eric,
    FMS may only apply to current row.  There is no way to get any other fixed row.
    Thanks,
    Gordon

  • Need to get sequence value in another column in oracle

    Hi ALL,
    I have sql query as below
    select header_id,order_number from oe_order_headers_all.
    and data it is displaying as
    heder_id     order_number
    111            500001
    121            500400
    I need to display  another field with some sequence value like as below
    id     heder_id     order_number
    1      111                    500001
    2      121                    500400
    so how to get sequence value in another column please help me on this.
    Thnaks

    You can just use ROWNUM Pseudocolumn
    select rownum id, header_id,order_number from oe_order_headers_all

  • Update one column while getting the value in another column

    Is it possible to in one single SQL statement update two columns in a table while at the same time obtaining the value of another column, on the same row, in the same table, and independently (that is, the update of the columns has nothing to do with the data that I want from another column)*?* Of course, I can do this in two operations, one being a "select" and the other one being an "update", but since I am in the same table and even on the same row, is it really necessary to make TWO database calls? That's why I want to combine the the two SQL-statements, for reasons of presumed effiency.

    jsun wrote:
    Is it possible to in one single SQL statement update two columns in a table while at the same time obtaining the value of another column, on the same row, in the same table, and independently (that is, the update of the columns has nothing to do with the data that I want from another column)*?* Of course, I can do this in two operations, one being a "select" and the other one being an "update", but since I am in the same table and even on the same row, is it really necessary to make TWO database calls? That's why I want to combine the the two SQL-statements, for reasons of presumed effiency.Two statements != two database calls.
    At least not in terms of SQL.
    JDBC requires a 'statement' but in SQL (depending on the data source) that can include multiple statements. An obvious example of this is a stored proc but there are other ways as well.

  • Summing Selected Rows in Column Depending on Value in Another Column

    I'd like to sum only the values in selected rows in a given column depending on the value of another column in the same row. For example, suppose I have a table (please disregard the underscores, needed for correct alignment):
    ___A____B____C___D
    1__5___10___15___0
    2_20___25___30___1
    3_35___40___45___1
    4_50___55___60___0
    5__sum(D=1)
    In cell B5, I'd like to compute the sum of only rows in column B for which the value of the corresponding column D is 1. In this case B5 would be 65.
    How can I do this using functions? Is it possible to do it for a variable range of rows without specifying each row individually?
    Thanks,
    Dave

    You should place your formula to other collumn then calculated ones or in another table. You will be able to calculate whole collumns with: =SUMIF(D;“=1”;B)
    Formula for your example is: =SUMIF(D1:D4;“=1”;B1:B4)
    VB

  • In the app "Numbers" I want to paste in many rows in to columns. And each row separated. Now it's getting all in one column

    In the app "Numbers" I want to paste in many rows in to columns. And each row separated. Now it's getting all in one column when I try to paste.
    Fact is that I have a 4 pages list with about 50 rows of single words and I want all that in columns

    Hey joshuafromisr,
    If you resintall iTunes, it should fix the issue. The following document will go over how to remove iTunes fully and then reinstall. Depending on what version of Windows you're running you'll either follow the directions here:
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    http://support.apple.com/kb/HT1925
    or here:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    Best,
    David

  • 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.

  • Convert rows to single column using t-sql

    Hi All,
    I have a table with 7 columns, et say..
      ID ,PatientName,Date,Time,Room_Num ,Specialized, DoctorName
    My source date looks like this..
      ID      PatientName     Date          Time    Room_Num  Specialized   DoctorName
       1         Sam        10/02/2010      10:00     4         Heart        
    John
       1         Sam        10/02/2010      10:00     4         Lungs        
    Harris
       2         Jones      11/12/2011      11:00     1         Lungs        
    Bob
       3         Jim        12/05/2001      01:00     2         Kidney       
    Greg
       3         Jim        12/05/2001      09:00     2         Eye          
    Roby
       1         Sam        12/22/2010      11:00     1         Heart        
    John
       1         Sam        12/22/2010      11:00     1         Lungs        
    Harris
    My out put should look like this..
       ID      PatientName     Date             DoctorName
       1         Sam        10/02/2010           John,Harris ( Need to be in 1 row because - ID, PatientName, Date is same)
       2         Jones      11/12/2011            Bob       ( Need to show as it is due to no repeatition
    of ID)
       3         Jim        12/05/2001            Greg,Roby   ( Need to be in 1 row because - ID, PatientName,
    Date is same)
       1         Sam        12/22/2010            John,Harris ( Need to be in 1 row because - ID, PatientName, Date is same)
    I am using below query to get above results but I am getting wrong results..Need some help in tweaking the query...
     SELECT DISTINCT ID ,PatientName , Date 
             ,STUFF(( SELECT ',' + DoctorName 
              FROM SampleTable ST1
              WHERE ST1.ID=ST2.ID
              FOR XML PATH('')),1,1,' ') AS DoctorName
              FROM SampleTable1 ST2
    GROUP BY ID ,PatientName , Date
    With above query I am getting results like this...
      ID      PatientName     Date             DoctorName
       1         Sam        10/02/2010         John,Harris ,John,Harris ( here John,Harris are repeating twice because of 4th row)
       2         Jones      11/12/2011         Bob      
       3         Jim        12/05/2001         Greg,Roby   
       1         Sam        12/22/2010         John,Harris ,John,Harris ( here John,Harris are repeating twice because of 1st row)
    Create table statement:
    Create table SampleTable
    ID Int null,     PatientName  varchar(25) null,   Date  datetime null,  Time varchar(10) null,   Room_Num int null, Specialized  varchar(20) null, DoctorName varchar(20) null
    Insert statement:
    Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam','10/02/2010' ,'10:00',4 ,'Heart','John')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1, 'Sam','10/02/2010' ,'10:00'   ,  4    ,     'Lungs','Harris')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 2, 'Jones' ,'11/12/2011'  ,    '11:00',1, 'Lungs',  'Bob')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values  ( 3,'Jim' ,'12/05/2001'    ,  '01:00',2,'Kidney' ,  'Greg')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 3,'Jim' ,'12/05/2001'     , '09:00',2,'Eye' ,   'Roby')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam' ,'12/22/2010'     , '11:00',1,'Heart', 'John')
     Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam', '12/22/2010'     , '11:00',1 , 'Lungs','Harris')
    I need help to tweak my query.
    Thanks,
    RH
    sql

    WITH cte AS(
    SELECT [ID]
    ,[PatientName]
    ,[Date]
    ,[Time]
    ,[Room_Num]
    ,[Specialized]
    ,[DoctorName]
    ,ROW_NUMBER() OVER(PARTITION BY [ID],[PatientName],[Date] ORDER BY Time) as RowID
    FROM [test].[dbo].[SampleTable]
    SELECT
    cte.[ID]
    ,cte.[PatientName]
    ,CAST(cte.[Date] as DATE) as [Date]
    ,STUFF((SELECT ',' + c.[DoctorName]
    FROM cte c
    WHERE c.ID=cte.ID AND c.PatientName=cte.[PatientName] AND c.[Date]=cte.[Date]
    FOR XML PATH(''),TYPE).value('.','varchar(max)')
    ,1,1,'') AS [DoctorName]
    FROM cte
    WHERE cte.RowID=1

  • Get ID from selected row in data table

    Hi!
    Does someone know how to get ID from row on which I click a button or link?
    getRowData() doesnt work!
    Or any other method in jsp or just something to get the ID from selected row?
    Thanks!!!

    Hi,
    I have a table with 3 columns, where column 1 represents the key, column 2 represents the data and column 3 displays the "details"-button. If you use
    String key =(String)outputText1.getValue();
    the variable key contains the key value of the row of the column in which the "details"-button was clicked. (outputText1 is the Output Text field of the first column).
    Problem with this is that the key Value must be displayed in the table but maybe it works if the OutputText Field is not rendered, too. If anyone has another (maybe nicer) solution for the problem i would be pleased to see it here.

  • Conditional inclusion of column cells based on value in another column?

    I was wondering if something like the following is possible -- I've looked through the forums and Numbers user guide but can't figure it out:
    Suppose I have a column A of sales figures, and columns B and C which basically have different attributes (say, color (yellow or green), size (small or large), and material (cotton or polyester)).
    I want to run basic statistics on various combinations: e.g. all yellow items regardless of size, all green cotton items regardless of size, all large yellow items regardless of material, etc.
    I want to be able to specify something like this:
    'Compute the average of every cell in column A where column B=="green" and column C=="large"'
    Is there a good way to go about doing this? Would I want to attack the problem using categories, sorting, and multiple tables? Or is there a way to conditionally include cell values from a range based on the value of that row's cell in another column?
    Thanks for any help.

    All I can think of to solve the quartile and median functions is to have another table of the same size as your original table that gets populated with just the items that match. Then you can do the quartile and median (and average) on that table. It's a one-at-a-time affair; you can only do one selection of size, color, and/or material at a time but you can get the median, mean, and quartiles of it. Of course, you could have multiple copies of this second table if you want to do more than one comparison at a time.
    In the attached file, unhide the hidden rows in Table 2 to see the formulas that do all the work.
    [files.me.com/pwb3/6hobt0.numbers.zip]
    Message was edited by: Badunit
    Message was edited by: Badunit

Maybe you are looking for