Groups | Blog | Home
all groups > sql server reporting services > march 2005 >

sql server reporting services : Create Dynamic Table of Contents and Indexes



Jeff A. Stucker
3/2/2005 7:23:04 PM
Not currently. The closest thing available right now is a Document Map.
This creates a bunch of bookmarks when you export to PDF, so that would
create an indexed report/PDF for you.

--
Cheers,

'(' Jeff A. Stucker
\

Business Intelligence
www.criadvantage.com
--------------------------------------
[quoted text, click to view]

Tobby Lee via SQLMonster.com
3/2/2005 11:22:33 PM
I was wondering if someone can tell me if there is a way to create a
dynamic table of contents and index for a report that is run.

For example, I need to create a directory of physicians based on a search
query of our database. So each report run would contain a different list of
doctors and locations, and on each query of the report the doctors would
show up on different pages of the report. I want to be able to create a
table of contents and an index for the report that will list the page
number the doctor first shows up on.

With MS Access VBA, I was able to do this by using the print event, in
which I would add each record to the access database table which contains
the table of contents, while the report was printing and therefore creating
the table of contents.

Is there a way (similiar) with SQL RS that I can accomplish this task?

--
Brian Bischof
3/3/2005 5:25:37 PM
Crystal Reports can do it, but it has to put it at the last page (it
generates the page numbers as it goes and accumulates them for display when
finished printing the records). Not an ideal solution for a TOC.


Brian Bischof
www.CrystalReportsBook.com



[quoted text, click to view]

Tobby Lee via SQLMonster.com
3/3/2005 5:42:13 PM
Thanks for your response Jeff. Do you know if Crystal Reports or any other
reporting solution can handle the task of creating a Table of Contents and
document Index?

--
Chris McGuigan
3/4/2005 2:48:50 AM
This is a multipart message in MIME format

--Xananews.1.2.3

I was given a 'sleazy hack' to do this in RS, it requires the report to
be run twice once so it can work out the page numbers, second time it
can use them in the table of contents. If the table is going at the end
you may be able to change to a run once version! Good luck!
I never said it would be easy!

I've attached the file, and copied it below for those viewing via web.

-- ------------------------------

Unfortunately, there's currently no good way to build a table of
contents.

And even adding defined execution order isn't going to help, since
pagination happens as a completely separate step from the rest of the
report. This is because you can request the same report with different
page
size/margin settings (and even an entirely different rendering target,
which
could radically change pagination). Under normal circumstances, we don't
want to force reexecution of the entire report just because you change
your
margins.
To handle table of contents type operations, we're going to (eventually)
have to implement an entirely new mode wherein we know that the body of
the
report contains references to page numbers, which will force the entire
report to reexecute if pagination information changes.

In the mean time, there's no general solution for the table of contents
problem.

But... Since you're doing this in a batch once a month, you may not
need a
fully general solution.

Without further ado, here's Sleazy Hack #792 ("Simulating Table of
Contents
in Batch Reporting Scenarios"):

1. Write a custom assembly containing a class that can write rows to a
TableOfContents table in your database.
Have shared methods for both initializing the TOC and writing a new
row
to the TOC.
Note: Don't forget to give it database permissions in the CAS file
when
you deploy it to your server.
See the documentation for details on custom assemblies.
2. In the Code section of the report, call the TOC initialization in
the
OnInit() event.
3. At the start of each section you want to appear in your TOC, put a
hidden textbox that contains the label you want to appear in your TOC.
4. In the page header, put a hidden textbox with something like the
following expression:

=Code.MyTOCClass.AddToTOC(Globals.PageNumber,ReportItems!Textbox1.Value
& ReportItems!Textbox2.Value & ReportItems!Textbox3.Value)
Texbox1, Textbox2 and Textbox3 are the names of the hidden textboxes
from step 3 (since only one will appear on any given page, the rest
will be
empty)
5. Add a dataset to your report which selects from the TableOfContents
table
6. Display the results of the TOC data set in a table at the end of
your
report*
7. Run the report twice. The first time will initialize the TOC. The
second time will use the values from the previous run.

* If you want it at the beginning, you'll either need to run the report
three times (the first to get some rows into the TOC table, the second
to
get the numbers populated correctly and the third to use those numbers)
or
you'll need to make sure the TOC table has the right number of rows to
begin
with (perhaps by not emptying it from the previous month) otherwise your
page numbers will be incorrect due to the TOC pushing things around.
This
isn't an issue if your TOC is only one page long and has PageBreakAtEnd,
however.

-- ----------------------------------------


[quoted text, click to view]


--Xananews.1.2.3
Content-Type: Application/Octet-Stream; name=Sleazy Hack #792.txt
Content-Transfer-Encoding: base64

VW5mb3J0dW5hdGVseSwgdGhlcmUncyBjdXJyZW50bHkgbm8gZ29vZCB3YXkgdG8gYnVpbGQgYSB0
YWJsZSBvZiBjb250ZW50cy4NCg0KQW5kIGV2ZW4gYWRkaW5nIGRlZmluZWQgZXhlY3V0aW9uIG9y
ZGVyIGlzbid0IGdvaW5nIH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IHlvdSB3YW50IHRvIGFwcGVh
ciBpbiB5b3VyIFRPQy4NCjQuICBJbiB0aGUgcGFnZSBoZWFkZXIsIHB1dCBhIGhpZGRlbiB0ZXh0
Ym94IHdpdGggc29tZXRoaW5nIGxpa2UgdGhlDQpmb2xsb3dpbmcgZXhwcmVzc2lvbjoNCiAgICA9
Q29kZS5NeVRPQ0NsYXNzLkFkZFRvVE9DKEdsb2JhbHMuUGFnZU51bWJlcixSZXBvcnRJdGVtcyFU
ZXh0Ym94MS5WYWx1ZQ0KJiBSZXBvcnRJdGVtcyFUZXh0Ym94Mi5WYWx1ZSAmIFJlcG9ydEl0ZW1z
Tobby Lee via SQLMonster.com
3/4/2005 9:58:33 PM
You would think that with day and age, Microsoft would be smart enough to
figure out that people might want to create a table of contents.

Thanks Chris, I'll give it a try.

--
Jeff A. Stucker
3/7/2005 5:32:05 PM
Yeah, but I cut the MS guys some slack on RS features. They have created a
tremendous reporting platform from the ground up in just a couple of years.

I hear they were going to release it with SQL 2005, but bumped it up due to
early demand. Gotta like that. In any case, I'm having fun with it. All
in all, even with its limitations, it's better than any other reporting
solution I've used to date.

</rahrah>
--
Cheers,

'(' Jeff A. Stucker
\

Business Intelligence
www.criadvantage.com
--------------------------------------
[quoted text, click to view]

Chris McGuigan
3/8/2005 3:36:13 AM
I second that. I ditched the last CR report from our organisation two
weeks ago. I even had a pint or two to celebrate!

I always thought CR was overpriced for what it was, funnily enough now
I don't use it I seem to be getting free upgrades from them! Do you
think they are a little worried? ;)

Chris



[quoted text, click to view]
Dlloyd
5/5/2005 6:06:07 AM
Chris...

Do you have some sample code or can you point me to something in the online
reference on how to add rows to a table from a custom class.

Dave

[quoted text, click to view]
Dlloyd
5/5/2005 6:58:03 AM
Never mind I misread your solution the first time.

Dave

[quoted text, click to view]
Chris McGuigan
5/5/2005 7:05:35 AM
Hi,
I haven't actually used this hack so I don't have an RDL file for you.
Try Tobby Lee, he said he was going to try it out.
If you are stuck creating the custom assembly, have a look at this site;
http://blogs.sqlxml.org/bryantlikes/articles/824.aspx?Pending=true

There are loads of ways to add rows to tables in VB (sorry I don't do
C).
I prefer sending raw SQL commands, but that's just the way I am!
If you're using old ADO (2.6 - 2.8) you will need a connection object
first then you can create a command object and issue a SQL 'insert'
statement. Below is an example BUT it is not 'best practice' nor
particularly efficient in the form I have given you. It should be
enough to get you going though, I'd suggest you get a book on the lines
of SQL for Developers or on ADO.Net (or earlier);

You will need to add a reference to an ADO namespace to your project
for this to work. ADO.Net is significantly different to previous
versions of ADO.

Heres the code;

Public Sub AddLine(Value1 As String, Value2 As String)
Dim oCon As ADODB.Connection


Set oCon = New ADODB.Connection

'Open a connection to the database
'
oCon.ConnectionString = "Provider=SQLOLEDB; Data Source=YourServer;
InitialCatalog=YourDB; User Id=yourid; Password=yourpassword"
oCon.Open

'Set up a command to do the INSERT
'
Set oCon.CommandText = "Insert Into YourTable (Fieldname1,
Fieldname2) Values ('" & Value1 & "','" & Value2 & "')"

'Actually INSERT the record
oCon.Execute

oCon.Close
Set oCon = Nothing
End Sub


Hope it helps ...
Chris



[quoted text, click to view]
AddThis Social Bookmark Button