ADO,SQL,slow,running,mulitple,SELECT,Statemen
Quick Search for:  in language:    
ADO,SQL,slow,running,mulitple,SELECT,Statemen
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 132,008 lines
 Jobs: 161 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
List Records
By Edito P. Aspra Jr. on 8/26


DSN Less Connection to SQL Server Database
By alpesh shah on 8/26


Click here to see a screenshot of this code!Database Driven Select Menu w/ default select
By Jayson Starkey on 8/26

(Screen Shot)

A Simple guestbook in ASP
By Matthew Meadows on 8/25


Simple GuestBook or Feedback Page Requiring No Database Implementation
By Ken Alabi on 8/25


if i remember, this is a M. Harris code sample
By ask on 8/24


MTS Registration Script
By Igor Krupitsky on 8/23


Click here to see a screenshot of this code!Creating Windows Users with ASP and ADSI
By jamespwalters on 8/23

(Screen Shot)

News Poster (Advanced)
By Martin Kilbryde on 8/22


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

A ADO Data Shaping or Multiple SQL Select

Print
Email
 
VB icon
Submitted on: 2/27/2001 3:58:01 PM
By: Rob Gerwing  
Level: Intermediate
User Rating: By 5 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 18332 times.
 
(About the author)
 
     Do you have slow running mulitple SELECT Statements or long reports to fill on a web page. Use the Microsoft Shape Command. Learn to use ADO 2.1 and greater advance features. This code is great for three things, (1) Very fast way to do multiple SQL select statements and reports. (2) Great for databases not Normalized. (3) Avoids multiple nested single threaded ADO Record Sets loops which are very slow.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: A ADO Data Shaping or Multiple S
    '     QL Select
    ' Description:Do you have slow running m
    '     ulitple SELECT Statements or long report
    '     s to fill on a web page. Use the Microso
    '     ft Shape Command. Learn to use ADO 2.1 a
    '     nd greater advance features. This code i
    '     s great for three things, (1) Very fast 
    '     way to do multiple SQL select statements
    '     and reports. (2) Great for databases not
    '     Normalized. (3) Avoids multiple nested s
    '     ingle threaded ADO Record Sets loops whi
    '     ch are very slow.
    ' By: Rob Gerwing
    '
    ' Assumes:Basic ADO Recordset use in Mic
    '     rosoft Active server Pages. Basic Knowle
    '     dge of SQL "SELECT" statements.
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.6512/lngWId.4/qx/vb/scripts/ShowCode.
    '     htm    'for details.    '**************************************
    
    <%Response.Buffer = True
    Const adOpenForwardOnly = 2
    Dim connShape,strShape
    Dim objConn,objRS,objStartDate,objEndDate
    'ADO CONNECTION
    Set connShape = Server.CreateObject("ADODB.Connection")
    connShape.Provider = "MSDataShape" 'Tell ADO To expect MSShape Command In SQL Syntax
    connShape.Open "DSN=NAME-OF-ODBC-SOURCE" 'Insert your Data Source Name String
    'ADO RECORDSET
    Set objRS = Server.CreateObject("ADODB.Recordset")
    'Shape SQL Syntax
    [Available at Microsoft KB Article Q189657]
    'WHY DID I USE SHAPE AND NOT A JOIN?
    'Look at the 2nd and 3rd SELECTS, I need
    '     ed to retrieve a record associated to
    'order_id BUT the same field name "event
    '     _value" and different event_types.
    'Working Example -->
    	strShape = "SHAPE {Select order_id,f_name,l_name FROM Order_Table"&_
    	" WHERE l_name = 'SMITH' ORDER BY l_name} AS OrderData "&_
    		 "APPEND "&_
    		 "({ Select order_id, event_value, event_type FROM event" &_
    		 " WHERE event_type = 'UserStartDate' } " &_
    		 " RELATE order_id To order_id) AS STARTDATE, "&_
    		 " ({ Select order_id, event_value, event_type FROM event" &_
    		 " WHERE event_type = 'UserEndDate' } " &_
    		 " RELATE order_id To order_id) AS ENDDATE"
    'Open RecordSet
    objRS.OPEN strShape,ConnShape,adOpenForwardOnly
    Response.Write "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>"
    Do While Not objRS.EOF 'Looping through Parent Record Set
    'Take from Parent Record Set
    Response.Write("<TR><TD>" & objRS("order_id") & "</TD>")
    Response.Write("<TD>" & objRS("l_name") & ", " & objRS("f_name") & "</TD>")
    'StartDate 1st Child RecordSet No Loop, 
    '     EXPECTING ONLY ONE RECORD VALUE
    	'Must use "STARTDATE" as reference In SQL "AS STARTDATE"
    	Set objStartDate = objRS("STARTDATE").Value 
    	if objStartDate.Eof = True Then
    		Response.Write("<TD> </TD>")
    	Else
    		Response.Write("<TD>" & objStartDate("event_value") & "</TD>")
    	End if
    	objStartDate.Close
    'EndDate 2nd Child RecordSet Loop Used,E
    '     XPECTING MORE MULTIPLE RECORD VALUES
    	'Must use "ENDDATE" as reference In SQL "AS ENDDATE"
    	Set objEndDate = objRS("ENDDATE").Value
    	if objEndDate.Eof = True Then
    		Response.Write("<TD> </TD>")
    	Else
    		Response.Write("<TD>")
    			While Not objEndDate.Eof
    				 Response.write (objEndDate("event_value") & ",")
    			objEndDate.MoveNext
    			Wend
    		Response.Write("</TD>")
    	End if
    		objEndDate.Close
    Response.Write "</TR>"
    objRS.MoveNext 
    LOOP
    Response.Write "</TABLE>"
    'Clean Up
    connShape.Close
    objRS.Close
    Set connShape = Nothing
    Set objRS = Nothing
    %>

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
2/28/2001 5:43:56 PM:Jerry MSDN User
I been looking how to do this, This 
loads the Recordset so fast. My old 
script had to find the indentifier, 
then loop through. My clients are very 
happy campers now!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/28/2001 8:11:26 PM:John W.
Thanks ... it helped.....
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/11/2001 6:29:56 PM:Eugene
Thanks. This is very Helpful.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/13/2002 1:35:38 AM:jimmy_thakkar
very veryy complexxxx
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/24/2002 1:21:33 AM:Fendi
It's definitely meaningful. I able to 
undertand the 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.