Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Cross-tab report: where to put the code?Cross-tab report: where to put the code?
Previous
 
Next
New Post
6/19/2006 4:57 AM
 
I am rewriting an application that i originally developed on IBuySpy. One the key reports is built on a cross-tab report. Last time around I did this using some self-modifying SQL that I found in the Gurus Guide to SQL. It worked fine but I cant help thinking that it violates some of the principles of three tier architecture to push so much business logic down to the database level. I also think that I may have been making hard work of it.

Is there any simpler ways of designing cross-tab reports, using multi-dimensional arrays and data grids for example? In a typical situation this would mean processing something like 50 thousand integers in IIS memory rather than making maybe a hundred calls on the database.

Are there any useful examples of large cross-tab reports in the Microsoft knowledge base, or in the Starter Kits, to look at?

All suggestions gratefully received.

Geoffrey Morton-Haworth www.yalaworld.net
 
New Post
9/29/2006 4:54 AM
 
In the end I decided not to do the cross-tab in dynamic SQL because there can be permission problems with dynamic SQL that don't occur with ordinary stored procedures.  Instead I used the following code which was obviously the source for the cross-tab in dnn's User Defined Tables.  Now all is working fine.

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Pivot transforms a normalized datareader into a pivoted datatable
        ''' </summary>
        ''' <param name="dataValues">DataReader to be pivoted into DataTable</param>
        ''' <param name="keyColumn">column in DataReader for each row</param>
        ''' <param name="pivotNameColumn">values to turn from rows to column names</param>
        ''' <param name="pivotValueColumn">values to pivot into appropriate columns</param>
        ''' <returns>The generated datatable</returns>
        ''' <history>From: Transforming a Normalized DataReader into a Pivoted DataTable
        ''' at http://weblogs.sqlteam.com/jeffs/archive/2005/05/11/5101.aspx 
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Shared Function Pivot(ByVal dataValues As IDataReader, ByVal keyColumn As String, ByVal pivotNameColumn As String, ByVal pivotValueColumn As String) As DataTable

            Dim tmp As New DataTable()
            Dim r As DataRow
            Dim LastKey As String = "//dummy//"
            Dim i, pValIndex, pNameIndex As Integer
            Dim s As String
            Dim FirstRow As Boolean = True

            ' Add non-pivot columns to the data table
            pValIndex = dataValues.GetOrdinal(pivotValueColumn) 'IssueId
            pNameIndex = dataValues.GetOrdinal(pivotNameColumn) 'Issue name

            For i = 0 To dataValues.FieldCount - 1
                If i <> pValIndex And i <> pNameIndex Then
                    tmp.Columns.Add(dataValues.GetName(i), dataValues.GetFieldType(i))
                End If
            Next i

            r = tmp.NewRow()

            ' now, fill up the table with the data:
            While dataValues.Read()

                ' see if we need to start a new row
                If dataValues(keyColumn).ToString() <> LastKey Then

                    ' if this isn't the very first row, add last one to the table
                    If Not FirstRow Then
                        tmp.Rows.Add(r)
                    End If
                    r = tmp.NewRow()

                    FirstRow = False

                    ' Add all non-pivot column values to the new row
                    For i = 0 To dataValues.FieldCount - 3
                        r(i) = dataValues(tmp.Columns(i).ColumnName)
                    Next i

                    LastKey = dataValues(keyColumn).ToString()

                End If

                ' assign pivot values to proper column, add new columns if needed
                s = dataValues(pNameIndex).ToString()

                If Not tmp.Columns.Contains(s) Then

                    tmp.Columns.Add(s, dataValues.GetFieldType(pValIndex))

                End If

                r(s) = dataValues(pValIndex)

            End While

            ' add that final row to the datatable
            tmp.Rows.Add(r)

            ' Close the DataReader
            dataValues.Close()

            Return tmp

        End Function

Hope this is helpful to someone else. 

Geoffrey

PS look up the article in the above comments for details of how to prepare the SQL input for this.

Geoffrey Morton-Haworth www.yalaworld.net
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Cross-tab report: where to put the code?Cross-tab report: where to put the code?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out