Pivot with header and details

I need to display data from both header and detail, details has to come from other table also
--CREATE TABLE
CREATE TABLE [dbo].[Table_Dept](
[DeptId] [int] NULL,
[DeptCode] [char](2) NULL,
[DeptName] [nvarchar](100) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[Table_Detail](
[Header_ID] [int] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[DescValue] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[Table_Header](
[Header_Id] [int] NULL,
[UserName] [nvarchar](50) NULL
) ON [PRIMARY]
--INSERT DATA
INSERT INTO Table_Dept (DeptId, DeptCode, DeptName)
VALUES (1, 'HO', N'Head Office'),
(2, 'BO', N'Branch Office'),
(3, 'RO', N'Reginal Office'),
(4, 'SO', N'Sub Division Office')
INSERT INTO Table_Header
(Header_Id, UserName)
VALUES (1, N'Ravi'), (2, N'Gopal'), (3, N'Deepa')
INSERT INTO Table_Detail
(Header_ID, Name, DescValue)
VALUES (1, N'ListNumber', N'1005'),
(1, N'PhaseCode', N'AA'),
(1, N'DeptCode', 'BO,RO'),
(1, N'City', 'Bangalore'),
(2, N'ListNumber', N'1006'),
(2, N'PhaseCode', N'AB'),
(2, N'DeptCode', 'SO,RO'),
(2, N'City', 'Delhi'),
(3, N'ListNumber', N'1007'),
(3, N'PhaseCode', N'AA'),
(3, N'DeptCode', 'HO'),
(3, N'City', 'Mumbai')
--EXPECTED RESULT
HeaderId
ListNumber
PhaseCode
DeptName
City
User
1
1005
AA
Branch Office,   Reginal Office
Bangalore
Ravi
2
1006
AB
Sub Division   Office,Reginal Office
Delhi
Gopal
3
1007
AA
HO
Mumbai
Deepa
ShanmugaRaj

see below code
SELECT *,
STUFF((SELECT ',' + DeptName
FROM Table_Dept
WHERE ',' + t.DeptCode + ',' LIKE '%,' + DeptCode + ',%'
FOR XML PATH('')),1,1,'') AS DeptName
FROM
SELECT h.Header_ID,
td.ListNumber,
td.PhaseCode,
td.DeptCode,
td.City
FROM Table_header h
INNER JOIN (SELECT Header_ID,
MAX(CASE WHEN Name = 'ListNumber' THEN DescValue END) AS ListNumber,
MAX(CASE WHEN Name = 'PhaseCode' THEN DescValue END) AS PhaseCode,
MAX(CASE WHEN Name = 'DeptCode' THEN DescValue END) AS DeptCode,
MAX(CASE WHEN Name = 'City' THEN DescValue END) AS City
FROM Table_Detail
GROUP BY Header_ID)td
ON td.Header_ID = h.Header_ID
)t
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
In case of not having department table...consider the dept code, where the values are now comming from table and
need result if the data is not displayed from table and they are static..
use case when 'Bo' then 'Branch Office'
when 'Ro' then 'Reginal Office'
when 'So' then 'Sub Division Office'
when 'Ho' then 'Head Office'
kindly suggest how to replace my above query
ShanmugaRaj

Similar Messages

  • Keeping heading and detail on the same page

    Hi, I have a report with a group header section and a detail section.  How can I keep the heading section and all the detail section on the same page without starting each group on a new page?
    The detail section will have either 2 or 3 records with some of the objects set to grow if the data doesn't fit on one line.  This results in several changes of group appearing on the same page which is what I want.  However, what I don't want is the header section on one page with the detail section on the next, or the header and some of the detail records on one page with the rest of the detail records on the next.  What I would like is the report to start a new page if the header and all the detail records don't fit on the same page but without starting a new page for every group change.  How can I achieve this?

    you can put the group header and details into a sub report on the old group header section.
    then hide the details section

  • Populate header and detail

    Hi,
    I have an internal table with the value below. I need to populate to header data line (1 record only)  and detail is an internal table
    When there is a change of customer, i need to copy 123 to header and 2 records of material (abc & xed), sales (100 & 200) and qty (10 & 12) to detail internal table.
    for customer 567, i need to copy to header and material aqs, sales 150 and qty 5 to detail internal table.
    May I know how can I achieve this?
    customer     material        sales      qty
    123              abc              100         10
    123              xed              200          12
    567              aqs              150           5
    877              abc               140         8
    Thanks
    Rgds

    Hello,
    As per my understanding, your requirement is that you have an internal table which has a combined data and you want to split it into headr and detail internal tables, based on the change of the customer number which is the first field in the combined internal table. If so then assume that it_com is the combined internal table and it_head and it_det as the header and detail interbnal tables respectively.
    First sor the combined internal table on customer number
    sort it_com by kunnr.
    Now loop across this table and on the event at new customer populate the header table and in the remaining loop populate the detail table.
    loop at it_com into wa_com.
      at new kunnr.
         wa_head-kunnr = wa_com-kunnr.
         append wa_head-kunnr to it_head-kunnr.
         clear wa_head-kunnr.
      endat.
    append the records from the combined table into the item table, whatever fields required
    endloop.
    Regards,
    Sachin

  • Internal table in Excel output with Header and Total

    Hi All,
    I have a selection-screen of a report where there is option to specify the path of a file to be stored in local PC. This Report gives output in ALV format which displays header and total of columns.
    Now, the requirement is, when the user specifies a path for the file in selection screen it should download in the specified location with header and total row into an excel format.
    The issue is, I have the internal table with data without total and header row and the total is getting displayed in the screen through ALV feature. I am not sure, how to give the same output in downloaded excel with header row and total as it is displayed on screen.
    Please let me know, if you have any suggestions.
    Thanks & Regards,
    Anshumita.

    try using TOP OF PAGE event and write the number of records in the header part.
    hope this will help.

  • File content conversion - sender adapter for Header and detail records

    Hi Experts,
                     I am receiving a field of fixed length content format.(Header)The first line of the file will follow the structure X having some fields and (DetailRecord)subsequent lines in the file will follow structure Y having somes fields.There is no record identifier for Header and Detail records.In one file first line is Header records and remaining subsequent line is DetailRecord.What are the parameters we have to set for sender file content conversion parameters as i donot have any key field and key field value.And in one file we have only one header records ( first line) and n number of detail records from 2nd line onwards.
    Thanks
    Deepak

    Hi
    Refer the below fourm link,
    Flat file whitout id
    Regards
    Ramg.

  • XMLSequence EXTRACT HEAD and DETAIL in ORACLE 9.2

    Hi, sorry about my english i am from argentine.
    I have this XML:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <arrayOfServicio >
        <Servicio>
            <Nombre>Autenticacion</Nombre>
            <Descripcion>ws</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>RequestTicket</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Consultas</Nombre>
            <Descripcion>wsConsultas</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetVigencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetSiniestralidad</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetAgrupados</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetSiniestralidadPorCuil</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Referencias</Nombre>
            <Descripcion>wsReferencias</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>TablaReferencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>ListadoReferencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>General</Nombre>
            <Descripcion>WsGeneral</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetServicios</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>eServicios</Nombre>
            <Descripcion>wseServicios</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>SetComunicacion</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>VentanillaART</Nombre>
            <Descripcion>wsVentanillaART</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>ObtenerNovedades</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Establecimientos</Nombre>
            <Descripcion>wsEstablecimiento</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetConsultaPorCuit</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
    </arrayOfServicio>
    I am working in ORACLE 9.2 and i wrote this query but the result is not correct, i need to join HEAD and DETAIL in some way but cannot do that...
      select extractvalue(value(head),'//Servicio/Nombre/text()') ,
            extractvalue(value(head),'//Servicio/Descripcion/text()'),
            extractvalue(value(head),'//Servicio/Activo/text()'),
            extractvalue(value(head),'//Servicio/Version/text()')
            ,extractvalue(value(detail),'//Metodo/Nombre/text()')
            ,extractvalue(value(detail),'//Metodo/Activo/text()')
            ,extractvalue(value(detail),'//Metodo/Version/text()')
      from arwt_ws_return x
          , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio'))) head
          , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio/MetodosEntity/Metodo'))) detail;
    Ii really appreciate your help.
    Thanks!

    Hi,
    You can do that by passing the head element to the second XMLSequence. That way you maintain the correlation between the parent and its children :
    select extractvalue(value(head), '/Servicio/Nombre') as srv_nombre
         , extractvalue(value(head), '/Servicio/Descripcion') as srv_desc
         , extractvalue(value(head), '/Servicio/Activo') as srv_activo
         , extractvalue(value(head), '/Servicio/Version') as srv_version
         , extractvalue(value(detail), '/Metodo/Nombre') as met_nombre
         , extractvalue(value(detail), '/Metodo/Activo') as met_activo
         , extractvalue(value(detail), '/Metodo/Version') as met_version
    from arwt_ws_return x
       , table(xmlsequence(extract(x.x_xmldoc, '/arrayOfServicio/Servicio'))) head
       , table(xmlsequence(extract(value(head), '/Servicio/MetodosEntity/Metodo'))) detail
    Please also note that :
    - you don't need a descendant axis (//) if you know the exact path
    - you don't need to go down to the text() node if you're using extractvalue
    Hope that helps.

  • Need information about FI document  with header and no items

    Hello Experts!
    I need your help for understanding the following subject :
    How is it possible when using F.13 to obtain a fi document with header without items sometimes,
    and fi document with header and items anothers times?
    We didn't saw/found customizing topics about that ( to enable or not header without items) Some exists?
    The only difference in the two cases are the document's type involded which are not the same.
    Regards,
    Josiane

    Hi,
    We verify  and compare everything.  it's the same everywhere except the document type of the invoice
    first case, F.13 create conciliation fi document with header and no items
    invoice ( doc. type YB )
    payment ( doc type ZT)
    conciliation ( doc type XZ )
    2th case, F.13 create conciliation fi document with header   and none items
    invoice ( doc. type YT )
    payment ( doc type ZT )
    conciliation ( doc type XZ )
    We match / compare  every fields and value  between invoice of 1st and 2tch case,  every fields and value between payment  of 1st and 2th case.
    ( we create  tests case in own integration system for reproduce  )
    We alse match / compare customizing of invoice type document YB and YT and  they seems identical...
    The procedure is the same with F.13 to do conciliation in both cases.
    we got same amount, same currency etc etc.
    We still didn't understand why with invoice type YT the conciliation document created is not the same as invoice type YB ...
    Nobody have idea ?

  • DMEE issue in header and detail record

    Hi Gurs,
    I am working in DMME payment medium .
    I have declared DMEE  header structure(00000001000001 ) as level 1 and detail (050000010020192             XX110000001) as also level 1.
    This is the output format i am getting.
    00000001000001                                                                               
    05000001002000             XX110000001                                                                               
    00000001000001                                                                               
    05000001002012            XX110000002                                                                               
    00000001000001                                                                               
    05000001002012             XX110000003                                                                00000001000001                                                                               
    05000001002011             XX110000004           
    But my requirment not lke this. i need to dispaly all detail items under one header also i need to increase the counter for every items starting from 2.
    Both header and detail are at  level 1.If i declared the detail as level 2 the output is not generated.
    This is what i need.                                                                               
    00000001000001                                                                               
    05000002002000             XXX110000001                                                        
    05000003002012             XXX110000002
    05000004002012             XXX110000003
    05000005002011             XXX110000004 
    Pls suggest me any solutions
    Thanks .

    NOT answered

  • DMEE Issues header and detail record

    Hi Gurs,
    I am working in DMME(PAYM) payment medium .
    I have declared DMEE header structure(00000001000001 ) as level 1 and detail (050000010020192 XX110000001) as also level 1.
    This is the output format i am getting.
    00000001000001
    05000001002000 XX110000001
    00000001000001
    05000001002012 XX110000002
    00000001000001
    05000001002012 XX110000003 00000001000001
    05000001002011 XX110000004
    But my requirment not lke this. i need to dispaly all detail items under one header also i need to increase the counter for every items starting from 2.
    Both header and detail are at level 1.If i declared the detail as level 2 the output is not generated.
    This is what i need.
    00000001000001
    05000002002000 XXX110000001
    05000003002012 XXX110000002
    05000004002012 XXX110000003
    05000005002011 XXX110000004
    Pls suggest me any solutions
    Thanks .
    Edited by: bala chandran on Oct 9, 2009 10:57 AM

    NOT answered

  • Help needed with header and upload onto business catalyst

    Can someone help with a problem over a header please?
    I have inserted a rectangle with a jpeg image in  background, in the 'header' section, underneath the menu. It comes up fine on most pages when previsualised, going right to the side of the screen, but stops just before the edge on certain pages. I have double checked that I have placed it in the right place in relation to the guides on the page.
    That's one problem.
    The second problem is that I tried to upload onto business catalyst, which got to 60% and refused to go any further, saying it couldn't find the header picture, giving the title and then u4833-3.fr.png. The picture is in the right folder I have double checked. And it isn't a png. Does it have to be ?
    And the third problem is that I got an email following my upload from business catalyst in Swedish. I am living in France.
    Can anyone help ? Thanks.

    Thanks for replying,
    How can I check the preview in other browsers before I publish a provisional site with BC?
    The rectangle width issue happens on certain pages but not others. The Welecom page is fine when the menu is active, also the contact page, but others are slightly too narrow. Changing the menu spacing doesn’t help - I was already on uniform but tried changing to regular and back.
    In design mode the rectangle is set to the edge of the browser, that’s 100%browser width right?
    Re BC I have about 200 images on 24 different pages and it seems to be having difficulty uploading some of them. But it has managed a couple I named with spaces but not others I named with just one name.
    Is there an issue on size of pictures ? If I need to replace is there a quick way to rename and relink or do I have to insert the photos all over again?
    I’m a novice with Muse with an ambitious site !
    Thanks for your help.
    Mary Featherstone
    Envoyé depuis Courrier Windows
    De : Sanjit_Das
    Envoyé : vendredi 14 février 2014 22:15
    À : MFeatherstone
    Re: Help needed with header and upload onto business catalyst
    created by Sanjit_Das in Help with using Adobe Muse CC - View the full discussion 
    Hi
    Answering the questions :
    - Have you checked the preview in Muse and also in other browsers ?
    - Does the rectangle width issue happens when menu is active , or in any specific state , Try to change the menu with uniform spacing and then check.
    - In design view the rectangle is set to 100% browser width ?
    With publishing :
    - Please try to rename the image file and then relink
    - If it happens with other images as well , see if all the image names includes strange characters or spaces.
    - Try again to publish
    With e-mail from BC :
    - Under preferences , please check the country selected.
    - If you have previously created partner account in BC and selected country and language then it would follow that, please check that.
    Thanks,
    Sanjit
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6121942#6121942
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6121942#6121942
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6121942#6121942. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Help with using Adobe Muse CC at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Table or report for TLB Shipments with header & item details

    Hi,
       Anyone can tell whats the table to view TLB Shipments with header & item details OR any other reports available to view?
    regards
    Arasu

    Hi
    I think following information might be helpful to you.
    http://help.sap.com/saphelp_sm40/helpdata/en/42/cb4e7efb0a136ae10000000a1553f7/content.htm
    Amol

  • Dimension with header and lines information

    Hi Experts
    I am using Oracle 11g for database , Oracle Admin Tool for repository creation
    Source : EBS R12
    Target : OBIEE
    In EBS R12 , I have gathered information about inspection [Inspection is our customized form in EBS , In Inspection we contain information about Jobs , WorkOrder , Asset etc]
    Some Inspection form have header information only and Some Inspection form have header and line information as well [there is no measures]
    I have confused about Header and Lines data in dimension tables ! how can I handle with it?
    In All inspection form some fields are common in header information
    Ryte now I have broke into two tables
    1: Dimension [Header and Lines]
    2: Factless Fact Table [Contains only FK]
    I want how can I merge two dimensions for get common information about different inspections?
    and how can I handle the Lines data in dimension table?
    Please proposed the best technique
    Best Regards,
    ZafaR

    Hi SqlCraze,
    According to your description, you want to load a “Header” table data with FileIdentifier, Code and ID columns and a “Detail” table data with Year, Type, LegalID and Amount columns from the xml file.
    Based on my research, the reason why you can only see 3 columns "FileIdentifier, Code, ID" in the XML Source is that there are only one element named includedFileHeader which contains those three columns.
    So if we want to achieve your requirement, we should add another element which contains four columns "Year, Type, LegalID, Amount" in the XML file. For more information, please refer to the following steps:
    Modify the XML file as below:
    <?xml version="1.0" ?>
    <Report xmlns="http://......... ">
     <includedFileHeader>
      <FileIdentifier>677ff108</FileIdentifier>
      <Code>XYZ</Code>
      <ID>17437</ID>
     </includedFileHeader>
            <IncludedFileDetail>
     <Year>2014</Year>
     <Type>P</Type>
     <LegalID>Test - 17437</LegalID>
     <Amount>969.33</Amount>
            </includedFileDetail>
    </Report>
    Use the modified XML in the XML Source, we can see two Output name: includedFileHeader and IncludedFileDetail.
    Connect to a SQL Server Destination with “IncludedFileHeader” as Output, another with “IncludedFileDetail” as Output.
    The following screenshot is for your reference:
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    If you have any feedback on our support, please click
    here.
    Katherine Xiong
    TechNet Community Support

  • Saving an invoice header and details in sql in one stored procedure.

    I would like to create an invoice in visual studio 2008 with a header and x amount of details (every time it's different). I want to be able to bring it all into sql encapsulated in one begin and commit transaction so that if there is an error anywhere
    on the way it can roll back and nothing will be saved to the database. 
    Debra has a question

    I have an article on my web site which includes a sample not too different from your situation. (In the sample data is read from a file, but that has little to do with the database communication.) Since you pass the data through TVPs, you can have the transaction
    in the stored procedure:
    http://www.sommarskog.se/arrays-in-sql-2008.html
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Show rtf file with header and footer  in Editor

    hi
    I want to open an rtf file which contains header and footer.The file i got is opened but the header and footer are not there.these all done with Editor.Please kindly go thru this and give me a solution.

    Hello,
    when you do yourEditorPane.getStyledDocument().dump(System.out), if you don't see and footer or header, you must write your own RTFEditorKit, but you must know how an RTF file is coded (but i don't know this coding...)

  • MySQL Sytax error with master and detail pages

    Master and Detail pages.
    I get an SQL error when I click on an Item in the Master
    page.
    “You have an error in your SQL syntax; check the manual
    that corresponds to your MySQL server version for the right syntax
    to use near 'ID = 16 LIMIT 0, 10' at line 1 “
    If I try to open the detail page I get
    “You have an error in your SQL syntax; check the manual
    that corresponds to your MySQL server version for the right syntax
    to use near 'ID = -1 LIMIT 0, 10' at line 1 “
    I created this pair by simply clicking on Insert/data object/
    master detail page.
    I have tried this various ways, but always get the same
    result.
    Is there a bug in CS3?

    Sorry I have solved it myself.
    I had accidentally put a space in a table header in the mySQL
    data bank.
    All works well now.

Maybe you are looking for

  • How do i find out what app was deleted by mistake on my iphone 5?

    How do I find out what app was deleted by mistake on my iphone5?

  • Coldfusion Error Really Bugging Me

    I am hosted by HOSTMYSITE and the other day i found out that they were using the old built in JDBC driver for connecting to MySql5 and as we know it doesnt work that well. So i told them and after alot of messages they created a new DSN using this ne

  • Version Naming Convention for Internet Explorer

    Notice on the far right side there is a Emoticon smiley face on the far right side.  This comes directly out of something I read and also did almost twenty years ago.  Did this cause the version update to 11?  I am not familiar with the metrics to ca

  • Can I create folders into iCloud?

    Can I create  folders into iCloud?

  • Microsoft SSAS and Oracle

    I have to build a data warehouse that brings about quick benefits realization. Though we are evaluating enterprise class EDW/ETL/BI tools and methodologies, we have an immediate need to deliver a simple data warehouse to the business. I am looking to