Link to home
Start Free TrialLog in
Avatar of Jasmin01
Jasmin01Flag for South Africa

asked on

C# -Exporting query results to excel, and manipulating the look of the spreadsheet

Hi.

I have a query that produces a result as seen attached, below, (Sample Result).  The result is correct, just not displayed correctly.
If you notice the "Acc No" field, it has a few duplicates.  I need to seperate the results to show the correct data on one side, and the incorrect on the other side.  For eg. Mrs.K Drier is the correct record, this should be on the left and the incorrect one, Mr S Drier, on the right.

I have attached, the sample of what the result should look like in Excel.
Sample-Result.txt
Sample-Format-Excel.xlsx
Avatar of Jared_S
Jared_S

For better responses to your question, how do you determine what is correct or incorrect data? In the case of duplicate account numbers, is the oldest account correct?

Is this something that could be handled easily in your query?
Avatar of Jasmin01

ASKER

Yes, the correct data is the oldest account.

Getting the query result is easy, its getting it in the format attached (Excel file) that's the problem.  If I could get it displaying correctly in SQL I can easily print it to Excel, but I have been struggling for days to get the query to display correctly, and have not been successful.  I can only get it as I had attached, one below the other.
ASKER CERTIFIED SOLUTION
Avatar of Jared_S
Jared_S

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for that.  My tables are a bit more complex.  The structure looks like this:

Table a               Table b             Table c
FK_LeadID         PK_LeadID        PKItemID
Name                 FK_ItemID        DateSold
Acc_No               LText                 PolicyNo

In order to get the Date Sold and the PolicyNo, I need to join Table b to the query and then join table c in order to get the result.  I'm trying to tweak your query to do this, but am not making much progress.
I figured it out with your help.  Thanks for the awesome query.