Late to the party.
If you are sans reporting tool, many databases have a PIVOT / UNPIVOT function for dealing with such problems in SQL.
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: SQL query and reports
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "SQL query and reports"
Collapse
-
You can use a matrix and put the AuditTypeID in the column group field, this would in give you a dynamic number of columns based on the distinct number of AuditTypeIDs you have across the rows. Effectively a Pivot table.
This vid demonstrates it in SSRS so should be applicable in RB3 although he parameterises which columns he wants to use but should give you the idea
The only caveat though is I'm pretty sure you would get a column for every AuditTypeID that appears in your dataset, and that would be applied across all your rows(invoices) regardless of whether each row has a values for each audittypeid
https://youtu.be/vgtVJf21EXU
the other option is to flatten the rows in the SQL statement and concatenate the AuditTypeID into a single string
http://www.sqlmatters.com/Articles/C...%20string.aspx
Leave a comment:
-
Originally posted by LondonManc View PostCan you be more specific on how you want your output to look?
The solution may vary - i.e. you could cobble together a little function to concatenate date and details or something similar.
Leave a comment:
-
Originally posted by original PM View PostHi Clever People,
can anyone help
We have an audit table within one of our systems which looks like
InvoiceNumber Date EmployeeID AuditTypeID Details
M12345 07/05/2010 0 4 Invoice Printed
M12345 09/03/2010 0 5 Payment Received £116.00
M12345 24/06/2010 0 5 Payment Received £462.00
M12345 10/06/2010 0 11 Letter 1 sent
However I want to write a report which then makes the items appear in a row such as that each invoice number has only 1 row with the various audit items going horizontally
Using report builder 3 to generate the reports
Anyone any ideas?
TIA
The solution may vary - i.e. you could cobble together a little function to concatenate date and details or something similar.
Leave a comment:
-
Not sure I've used report builder before. But a simple group by query should give you the result you desire.
Grouping by the invoice number, date and then audit item should give you the result you require. Straight forward group by query then throw that into your report
Might be worth putting an example of how you want the result set to look. Into a spreadsheet and posting a screenshot on here. Should be able to give you some more advice - should you still require it of course.Last edited by DanielSQL; 22 June 2015, 07:08.
Leave a comment:
-
Originally posted by darrylmg View PostThat sounds like a transposition.
You can do it in a stored procedure if you can program, or dump a basic report to Excel and transpose there.
Either way, I wouldn't recommend that format, because you don't know how many columns or length of data you're going to need to join together. You might run out of space to properly view it (if you know what I mean).
You might be beter off using a basic grouping function, which would group by invoice id, then have a date sorted sub-row for each of the audit details against that invoice.
This would probably be better because you could then quickly duplicate that report, changing it to group instead by date or account, or employee. Providing you with the differing views you might want to see if you were investigating fraud.
Leave a comment:
-
That sounds like a transposition.
You can do it in a stored procedure if you can program, or dump a basic report to Excel and transpose there.
Either way, I wouldn't recommend that format, because you don't know how many columns or length of data you're going to need to join together. You might run out of space to properly view it (if you know what I mean).
You might be beter off using a basic grouping function, which would group by invoice id, then have a date sorted sub-row for each of the audit details against that invoice.
This would probably be better because you could then quickly duplicate that report, changing it to group instead by date or account, or employee. Providing you with the differing views you might want to see if you were investigating fraud.
Leave a comment:
-
Originally posted by eek View Posthttps://msdn.microsoft.com/en-us/library/dd220467.aspx shows you how to create a stepped report which would give you something like
M12345
07/05/2010 0 4 Invoice Printed
09/03/2010 0 5 Payment Received £116.00
24/06/2010 0 5 Payment Received £462.00
10/06/2010 0 11 Letter 1 sent
I'm not sure how you merge detail rows to appear on a single row though...
tr '\r\n' ' ' < origfile > newfileLast edited by stek; 17 June 2015, 19:22.
Leave a comment:
-
Originally posted by original PM View PostHi Clever People,
can anyone help
We have an audit table within one of our systems which looks like
InvoiceNumber Date EmployeeID AuditTypeID Details
M12345 07/05/2010 0 4 Invoice Printed
M12345 09/03/2010 0 5 Payment Received £116.00
M12345 24/06/2010 0 5 Payment Received £462.00
M12345 10/06/2010 0 11 Letter 1 sent
However I want to write a report which then makes the items appear in a row such as that each invoice number has only 1 row with the various audit items going horizontally
Using report builder 3 to generate the reports
Anyone any ideas?
TIA
M12345
07/05/2010 0 4 Invoice Printed
09/03/2010 0 5 Payment Received £116.00
24/06/2010 0 5 Payment Received £462.00
10/06/2010 0 11 Letter 1 sent
I'm not sure how you merge detail rows to appear on a single row though...
Leave a comment:
-
SQL query and reports
Hi Clever People,
can anyone help
We have an audit table within one of our systems which looks like
InvoiceNumber Date EmployeeID AuditTypeID Details
M12345 07/05/2010 0 4 Invoice Printed
M12345 09/03/2010 0 5 Payment Received £116.00
M12345 24/06/2010 0 5 Payment Received £462.00
M12345 10/06/2010 0 11 Letter 1 sent
However I want to write a report which then makes the items appear in a row such as that each invoice number has only 1 row with the various audit items going horizontally
Using report builder 3 to generate the reports
Anyone any ideas?
TIATags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Reports of umbrella companies’ death are greatly exaggerated Yesterday 10:11
- A new hiring fraud hinges on a limited company, a passport and ‘Ade’ Nov 27 09:21
- Is an unpaid umbrella company required to pay contractors? Nov 26 09:28
- The truth of umbrella company regulation is being misconstrued Nov 25 09:23
- Labour’s plan to regulate umbrella companies: a closer look Nov 21 09:24
- When HMRC misses an FTT deadline but still wins another CJRS case Nov 20 09:20
- How 15% employer NICs will sting the umbrella company market Nov 19 09:16
- Contracting Awards 2024 hails 19 firms as best of the best Nov 18 09:13
- How to answer at interview, ‘What’s your greatest weakness?’ Nov 14 09:59
- Business Asset Disposal Relief changes in April 2025: Q&A Nov 13 09:37
Leave a comment: