Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2004, 02:03 AM
Authorized User
 
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reformatting data

Hi There
I have a nasty piece of SQL which queries 4 tables using Left & right joins, this is because each record may have many different categories associated with it and so a record is returned for each different category found ie : -
recid1 somemoredata category a
recid1 somemoredata category b
recid1 somemoredata category c
recid2 record2data category 1
recid2 record2data category 2

As you can see the net result of which is a recordset containing a lot of redundant data. Now I needed this reformatted similarly to output from the ado getrows method, ie Columns/Rows so that the categories were appended onto the end of one record so that the above example would be rendered as

recid1 somemoredata category acategory bcategory c
recid2 record2data category 1category 2

I did this but think my method was pretty inefficent, I did mine by using the dictionary object and a new array. If anyone is remotely interested I can post the code. I also worked out another way by just transferring data directly from the original array to a new 2-way array.

I also thought data shaping might cut down on the redundant data aspect, anyway all other thoughts are welcome.


 
Old April 22nd, 2004, 07:09 AM
Authorized User
 
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Decided to rewrite it using a combination of data-shaping and arrays
which gives me code similar to this :-

BTW if you're looking for response.write commands, this is the VB6 version. This seems to be an excellent way of removing all those extraneous lines cused by left & right joins.

Dim objConn As ADODB.Connection
Dim strConnString As String
Dim strSql As String
Dim rsMain As ADODB.Recordset
Dim rsInter As ADODB.Recordset
Dim rsCats As ADODB.Recordset
Dim arrData() As String
Dim arrIndx As Integer
Dim strCatType As String

  Set objConn = New ADODB.Connection
   objConn.Provider = "MSDataShape"

   strConnString = "Provider=MSDataShape;" & _
           "Data Provider=SQLOLEDB;" & _
           "Data Source=<yourServer>;" & _
           "Initial Catalog=<your database>;" & _
           "User Id=<uid>;" & _
           "Password=<yourpassword>"

   objConn.ConnectionString = strConnString
   objConn.Open

   strSql = _
    "SHAPE { SELECT Vacancy.*, Location.Location FROM Vacancy, Location where Vacancy.LocId = Location.LocId ORDER BY VacDesc }" & _
    " Append ((" & _
    "SHAPE { SELECT * FROM VacCat ORDER BY VacId} as RSInter" & _
    " Append (" & _
    "{SELECT * FROM Categories ORDER BY CatDesc} AS RSCats" & _
    " RELATE CatId TO CatId))" & _
    " RELATE VacId TO VacId)"

   Set rsMain = New ADODB.Recordset
   rsMain.Open strSql, objConn
   'Our class recordset

   arrIndx = 0
   Do While Not rsMain.EOF
   If arrIndx = 0 Then
      ReDim arrData(arrIndx)
   Else
      ReDim Preserve arrData(arrIndx)
   End If
   arrData(arrIndx) = rsMain("VacId").Value & " " & rsMain("VacDesc").Value & " " & rsMain("Location").Value
    Set rsInter = rsMain("RSinter").Value
    Do While Not rsInter.EOF
        Set rsCats = rsInter("RSCats").Value
        Do While Not rsCats.EOF
            ' Processing here
            If rsCats("CatType").Value = 1 Then
               strCatType = " Client - "
            Else
               strCatType = " Activity - "
            End If

            arrData(arrIndx) = arrData(arrIndx) & strCatType & rsCats("CatDesc").Value & "/"
            rsCats.MoveNext
        Loop
        rsInter.MoveNext
     Loop
     arrIndx = arrIndx + 1
     rsMain.MoveNext
   Loop

   For arrIndx = 0 To UBound(arrData)
       Debug.Print arrData(arrIndx)
   Next

   'Clean up...
   rsMain.Close
   Set rsMain = Nothing

   'Clean up...
   rsInter.Close
   Set rsInter = Nothing

   'Clean up...
   rsCats.Close
   Set rsCats = Nothing

   objConn.Close
   Set objConn = Nothing



 
Old April 22nd, 2004, 07:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Reagrding you First post, I am not sure about the column names there. But something like this should work for you. You can take some ideas from this thread

http://p2p.wrox.com/topic.asp?TOPIC_ID=12476

OR

http://msdn.microsoft.com/library/de...qd_14_04j7.asp

Hope that helps.
Cheers!

-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in e-mail structure sending data from data tiawebchd General .NET 3 May 5th, 2008 08:07 AM
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
reformatting text file naigba C# 1 June 11th, 2007 05:02 AM
Transfering data from csv file to data base g_vamsi_krish ASP.NET 1.0 and 1.1 Professional 2 May 16th, 2006 11:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.