c# - Exporting Data To Excel, with Jagged Columns due to dynamic data? -


I have an interesting problem where I need to create an Excel data dump with some data in the database, but it will be something simple Compared to I have some complex data to merge, below is an example of the data that I have to deal with.

TblGeneralInfo

  RecordId | Record name | Date | Cost 1 | Examination Entry | | 1/1/2010 | 2.0 2 Test Entry 2 | 1/1/2010 | 20.25  

TblRandomInfo

  Record ID | Questionnaire | Answer 1 | your name? | Bob 1 Your title? | Builder 2 | Favorite movie | Matrix 2 | Favorite car | Mustang  

The end I need is the following

  record id | Record name Date | Cost | | | | 1 | Examination Entry | 1/1/2010 | 2.0 | your name? | Bob | Your title? | Builder 2 | Examination Entry 2 | 1/1/2010 | 20.25 | Favorite move | Matrix | Favorite car | Mustang  

I am now using SQL Server 2005 for reporting and application for ASP.NET 3.5 (C #). I'm looking for the best way to do this. The number of objects in "TblRandomInfo" is variable, and can be in the form of 20-30 Q / a couple per record. Due to the nature of the data I can not easily do one pivot, even a dynamic axis.

Editing

A solution is valid on either SQL Server or C #. But note that information in tblRandomInfo may break the line.

What is the problem that you will create a table like the T-SQL query that you want?

I'm sure this can be done, but why not make the output in the C # application? The easiest thing to write to CSV is to write. Drag the TblGeneralInfo record

  • Drag the TblRandomInfo record
  • For each record in TblGeneralInfo, RecordAd, RecordName, TblRandomInfo records records matching TbGeneralInfo records for each record, type question and answer < / Li>
  • New Line
  • Of course, you can do this with interop, as long as you have Excel installed on the server, but it's a little over CSV Adds complexity to profit


    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -