RowNum for header and detail for XMLNodes using XQuery Sqlserver

Hi All,
I have this xml.
declare @xml xml
set @xml =' <StudentsData>
<StudentData>
<Name>AAA</Name>
<subjects>
<subject>
<Name>computers</Name>
<marks>30</marks>
</subject>
<subject>
<Name>Maths</Name>
<marks>40</marks>
</subject>
</subjects>
</StudentData>
<StudentData>
<Name>BBB</Name>
<subjects>
<subject>
<Name>Science</Name>
<marks>30</marks>
</subject>
<subject>
<Name>Physics</Name>
<marks>40</marks>
</subject>
</subjects>
</StudentData>
</StudentsData>'
I am able to get the proper data by querying like below.
select
s.n.value('(Name/text())[1]', 'varchar(50)') as StudentName ,
z.c.value('(Name/text())[1]','varchar(50)') as SubjectName ,
z.c.value('(marks/text())[1]','int') as Marks
from
@XML.nodes('/StudentsData/StudentData') as S(N)
CROSS APPLY s.n.nodes('subjects/subject') z(c)
But I want to include the header_id and detail_id to for these records using a variable like below.
eg: declare @header_id =100
      declare @detail_id = 1000
I want the output like below.
HeaderId DetailId StudentName SubjectName Marks
101 1001 AAA computers 30
101 1002 AAA Maths 40
102 1003 BBB Science 30
102 1004 BBB Physics 40
how do I get this using xquery.
Thanks in advance.

pls try
declare @xml xml
set @xml =' <StudentsData>
<StudentData>
<Name>AAA</Name>
<subjects>
<subject>
<Name>computers</Name>
<marks>30</marks>
</subject>
<subject>
<Name>Maths</Name>
<marks>40</marks>
</subject>
</subjects>
</StudentData>
<StudentData>
<Name>BBB</Name>
<subjects>
<subject>
<Name>Science</Name>
<marks>30</marks>
</subject>
<subject>
<Name>Physics</Name>
<marks>40</marks>
</subject>
</subjects>
</StudentData>
</StudentsData>'
declare @header_id int =100
declare @detail_id int= 1000
select @header_id+ROW_NUMBER() over(order by (select 1)) header_id,@detail_id+ROW_NUMBER() over(order by (select 1))detail_id,
s.n.value('(Name/text())[1]', 'varchar(50)') as StudentName ,
z.c.value('(Name/text())[1]','varchar(50)') as SubjectName ,
z.c.value('(marks/text())[1]','int') as Marks
from
@XML.nodes('/StudentsData/StudentData') as S(N)
CROSS APPLY s.n.nodes('subjects/subject') z(c)
vt
Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker

Similar Messages

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

  • Use different Layouts for Summary and Details in Drill down report

    Hi All,
    I have a 2 level drill down report in ALV.
    The summary report has certain fields and the Detail report has different fields. Now my problem is that when i use a default layout (with all fields of summary report) for the summary report, and drill down to the detail report i'm missing the fields on detail that are not in Summary. And if i save the default layout as default (with all fields of Detail) and go back to sumary, I'm missing the some other fields on summary (which are not on detail report).
    Is there a way to make different default layouts for each of those summary and detail reports:
    Also as the layouts are choosen by the user, i cannot hardcode any particular layout;
    So if the user chooses a layout for detail; it has to stay the same layout for the detail report if he goes to summary and then back to detail; unless the user changes the layout again.
    I'm using two different Layout types for each report. but i still cannot get the desired effect.
    Data:
          gt_layout_s             type slis_layout_alv,
          gt_layout_d             type slis_layout_alv,
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program       = g_repid
          is_layout                = <b>gt_layout_s</b>
          i_callback_top_of_page   = g_top_of_page
          i_callback_user_command  = g_user_command
          i_callback_pf_status_set = g_status
          i_save                   = g_save
          is_variant               = gs_variant
          it_fieldcat              = gt_fieldcat[]
          it_events                = gt_events[]
        importing
          es_exit_caused_by_user   = gs_exit_caused_by_user
        tables
          t_outtab                 = it_summary.
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program       = g_repid
          is_layout                = <b>gt_layout_d</b>
          i_callback_top_of_page   = g_top_of_page
          i_callback_user_command  = g_user_command
          i_callback_pf_status_set = g_status
          i_save                   = g_save
          is_variant               = gs_variant
          it_fieldcat              = gt_fieldcat[]
          it_events                = gt_events[]
        importing
          es_exit_caused_by_user   = gs_exit_caused_by_user
        tables
          t_outtab                 = it_detail_disp.

    Here is how you differentiate between the layout of two different grids. There is the parameter, IS_VARIANT in the function. You usually leave it empty or pass only the report name and username. <b>What you need to do is to pass unique string for each grids to the HANDLE field of the parameter IS_VARIANT.</b> You can probably hard code it as HEADER and DETAILS in your case. Once that is done, system identified that these two different layout for different grids.
    Regards,
    Ravi
    Note : Please mark all the helpful answers<u></u>

  • Receiver FCC Structure For Header and Trailer

    Hi Guys ,
    I need to go for receiver FCC for header and trailer  in PI .How the FCC in communication channel needs to be configured if I am taking a separate node for header and trailer in mapping .Output of the file should be as the file attached.
    Thanks.
    Regards.

    Hi,
    If you are using File communication channel as a reciver you can go with FCC.
    Use record set structure as : Header,detail,trailer.
    https://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
    Otherwise if you are going for SFTP to create the file ... follow the Indrajit suggestion..
    Still facing any issue.. Please let us know..
    Thanks,
    Sreenivas...

  • I have 2 macbooks each with an account for me and one for my wife. I use one Macbook logged in with my account and my wife uses the other Macbook only loged in on her account. We both make regular time-machine back-ups each on a separate external disk

    I have 2 Macbooks each with an account for me and one for my wife. I use one Macbook logged in with my account and my wife uses the other Macbook only logged in on her account. We both make regular time-machine back-ups each on a separate external disk. Is it possible to update her account on my macbook using her external disk without overwriting my stuff on the same Macbook and vice versa?

    Time Machine does not do individual accounts. It records the complete drive. So if you were to use her TM backup on your Mac it would make your Mac just like hers. Both yours and her account on your MAC.
    Just copy the missing files over from her Mac to yours. If there are differennt programs on each then they would need to be installed on both.

  • HT204053 i use one apple id for icloud and one for itunes  and now it wont let me since i reset my phone now  i up graded to iphone 4s still the same problem

    please help me fix this problem I have one id  for icloud and one for itunes that i share with my husband

    If the old ID is an earlier version of your current ID, temporarily recreate the old ID by going to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iPhone, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iPhone when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • I have a private Adobe ID and I have a Lightroom Testversion running there! Now my university gave me access to Creative Cloud for Teams and I want to use my Lightroom catalogues with this ID! How can I do this?

    I have a private Adobe ID and I have a Lightroom Testversion running there! Now my university gave me access to Creative Cloud for Teams and I want to use my Lightroom catalogues with this ID! How can I do this?

    Hi,
    thank you, it’s done! The Chat helped me! Now I cannot go into this forum anymore with my old password, but that’s not a big problem.
    Best wishes,
    Christian
    Von: JimHess <[email protected]<mailto:[email protected]>>
    Antworten an: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
    Datum: Montag, 20. April 2015 18:38
    An: Christian Kogler <[email protected]<mailto:[email protected]>>
    Betreff:  I have a private Adobe ID and I have a Lightroom Testversion running there! Now my university gave me access to Creative Cloud for Teams and I want to use my Lightroom catalogues with this ID! How can I do this?
    I have a private Adobe ID and I have a Lightroom Testversion running there! Now my university gave me access to Creative Cloud for Teams and I want to use my Lightroom catalogues with this ID! How can I do this?
    created by JimHess<https://forums.adobe.com/people/JimHess> in Photoshop Lightroom - View the full discussion<https://forums.adobe.com/message/7454915#7454915>

  • How to generate Header and Trailer for a file

    Hi Guru
    How can we generate header and Trailer for a file
    EX:
    i want to generate header with date and trailer with record count from table.
    Sample file :
    20120120
    fwsfs
    adfwsfd
    adff
    afsadf
    afdwsg
    adgsg
    adgsgg
    asgdsag
    sdgasgdaf
    sdfsagfadf
    10

    Hi ,
    1.Create an interface to load data from oracle to file and set generate header as false option in IKM .
    2.Create variable get_current_date of alphanumeric datatype and implement logic SELECT to_Char(SYSDATE,'yyyymmdd') FROM DUAL under refreshing tab
    3.Create variable get_record_count of numeric datatype and implement logic SELECT '<%=odiRef.getPrevStepLog("INSERT_COUNT")%>' FROM DUAL under refreshing tab
    4.Create a package
    Drag the get_current_date variable ,
    Drag odioutfile and paste the below logic OdiOutFile "-FILE=D:\ODI_TEST\emp.txt" "-CHARSET_ENCODING=ISO8859_1" "-XROW_SEP=0D0A" #GET_current_date in command tab
    Drag the interface
    Drag another variable get_Record_count
    Drag the odioutfile and paste the below logic OdiOutFile "-FILE=D:\ODI_TEST\emp.txt" -APPEND "-CHARSET_ENCODING=ISO8859_1" "-XROW_SEP=0D0A"
    #GET_RECORD_COUNT in command tab
    Link all these in sequence,save and run the package.
    OR Modify the IKM SQL to File Append to achieve same functionality.
    Thanks,
    Anuradha

  • Why yahoo/gmail retrieval and facebook app so so slow when in WIFI. But using the internet to check for emails and facebook is fast using the same WIFI connection??

    Why yahoo/gmail retrieval and facebook app so so slow when in WIFI. But using the internet to check for emails and facebook is fast using the same WIFI connection??

    Hi SandyS_VZW,
    Yes tried resetting the wifi connection and problem still persist.
    Here it is...to make it clear. Connected thru the same wifi at home...
    -> emails (yahoo/gmail) and facebook WEBSITES are working fine and fast when using/accessing thru a browser (chrome/samsung browser) - no problem with this.
    -> emails (yahoo/gmail) and facebook APP is soooooo sloooww (thru the App). Slow I mean comparing it to using their browser/websites... news feeds/emails refreshing so quickly but not when using the APP installed in Samsung Galaxy Note 4. Slow like - It will take around 5-10minutes just to get your emails and news feed refreshed.
    THIS HAPPENS ONLY WHEN CONNECTED THRU A WIFI which has a speed of 10-20mb. It is not happening when connected to the network data/plan.
    My wife has the same Samsung Galaxy Note 4 (coming from different provider at&t) - same setup (emails, fb app), same wifi connection, but she's not experiencing anything like it.
    Not sure why, I dont want to believe that while connected to a WIFI, Verizon is restricting anything and ******* me off to make me switch to my data plan connection everytime - which is Unfair!
    Was there a known issue similar about this case?
    thanks,

  • Can windows xp use a different sound card for itunes - I want to use a sound card for itunes and another for all other apps

    Can Windows XP use a different sound card for itunes - I want to use a sound card for itunes and another for all ther apps

    To the best of my knowledge, Windows is not capable of setting a specific sound card based on the app being used, it's all or nothing.
    Try a google search or search the Microsoft site.

  • Can i use cdma for internet and gsm for phone at a time in Iphone4s?

    Can i use cdma for internet and gsm for phone at a time in Iphone4s?

    No. Phones sold by GSM carriers can't access CDMA at all and phones sold by CDMA carriers can only access GSM if they are a) unlocked and b) in an area where there is not CDMA.
    Best of luck.

  • Unsupported version Error while generating header and footer for the PDF

    hi
    I want to genrate header and footer for the PDF file however on the call of the EndPage class i got a Unsupported Version Error Unsupported major minor Version Error and Class loader Define class
    What has gone wrong ?.

    Can you provide more information about what you were trying to do? In particular, what does your code like like?
    Also, can you include the stack trace, and the complete error message?

  • How to create schema for Header and Footer with pipe delimiter file BPEL11g

    Hi all,
    I have issule creating Schema for Header and Footer with body file .The file format is Pipe delimiter.The following format below like is...
    Softeware Components:File Adapter(Read) 11g,
    1|1211|000|577|5444
    1|0000|57|6988|4554|sfdgh|5448|3333|ituu|44445|55546|544|788|7788
    1|0000|57|6988|4554|sfdgh|5448|3333|ituu|44445|55546|544|788|7788
    1|0000|57|6988|4554|sfdgh|5448|3333|ituu|44445|55546|544|788|7788
    1|0000|57|6988|4554|sfdgh|5448|3333|ituu|44445|55546|544|788|7788
    1|0000|57|6988|4554|sfdgh|5448|3333|ituu|44445|55546|544|788|7788
    1|0000|57|6988|4554|sfdgh|5448|3333|ituu|44445|55546|544|788|7788
    1|4544|000|yted
    I hope get the sollution for this from this Forum..Please help me out..Thankyou.

    You mean how many rows or columns..?
    If coloumns means 5 and rows only one(1).

  • Prompting for password and username only when using dynamic parameters

    Post Author: Co3023
    CA Forum: Crystal Reports
    How do I stop CR XI prompting for password and username only when using dynamic parameters. When no dynamic parameters are used CR XI isn't prompting for the DB user name and password. The report is run from an application which passes the user name and password. I am using Oracle and the problem is both with the native oracle driver and the ODBC RDO driver.

    Post Author: jehanzeb
    CA Forum: Crystal Reports
    I didnt ask you to change it to static I said I took the parameters totally out of the report. Saved it. Then re-enter the dynamic parameters into the report and it worked for me. That might have worked for you, not sure why you changed it to static.
    Ok I have just created a quick report using dynamic parameters, it didnt ask me for the username password.
    Can you create a sample report - just to test the db? and see if it works? add only 1 or 2 fields in the report, create parameters (dynamic) and see if it works
    why don't you embed the username and password in your application, it won't ask for username password then.

  • Want to install Indesign on my new computer but am having trouble. First bought CS2 in 2009 and upgraded to 7.5 in 2011. I have the serial numbers for both and was able to use it on my last computer. Where do I start?

    want to install Indesign on my new computer but am having trouble. First bought CS2 in 2009 and upgraded to 7.5 in 2011. I have the serial numbers for both and was able to use it on my last computer. I don't use Indesign that often but there are some projects that it's good for. Where do I start?

    Lchrichton123 what version of InDesign specifically are you wishing to install?  You can find links to the installation files for the majority of Adobe Creative software titles at Other downloads

Maybe you are looking for

  • DVD Drive unmounts and crashes any app that tries to access it...help!

    Hi, I have a MacPro with a Pioneer DVD-RW DVR106d. All has been working well until recently. Yesterday, I started a project to encode my DVDs for Apple TV using Handbrake. When I insert a DVD, it spins up, mounts it, and allows normal operation. Howe

  • How to read device report for HP Deskjet 1510

    Hi HP, I can see from the software provided with this printer there is this option to print the device reports. Please assist on how to read this report because it consist of unknown coding and stuff.  I would appreciate if your side can help me on t

  • NAS Storage Suggestion

    I've got a small networked office (with a laptop and a desktop) and am hoping for suggestions for a reliable long term solution for an NAS storage device that I can connect to my Time Capsule via ethernet connection. I will be using this device to Ti

  • PE7 error (cannot open project):  ..\..\Src\Video\VideoSegment.cpp-55

    I am a rookie with PE7 and definitely not very tech-savvy compared to most on this forum, but I came to this site looking for assistance with a PE7 video project I have been working on for the last several weeks and now I'm afraid I have lost.  When

  • Color Management-Where is my error?

    30" Apple Cinema Display recently calibrated with Eye-One Display 2. Photoshop CS3 color space is North America General Purpose 2. I open Digital Color Meter, take a color (#5e90ba) from a web page in Safari. I make a new Photoshop document, fill it