SQL HELP - SELECT STATEMENT
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5249
Printed Date: 29 March 2026 at 12:01pm Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: SQL HELP - SELECT STATEMENT
Posted By: Mikeap
Subject: SQL HELP - SELECT STATEMENT
Date Posted: 24 August 2003 at 1:36pm
|
I need to select the TOP 16 rows and for each row, create a field so I can manually place it on a page (in a confined layout) without having to do all kinds of jibberish repeat region statements and what not.
Is this possible? If so, what is the statement to do it?
The page I am trying to do this on is @ http://www.rotsquad.com/tournament/brackets.asp - www.rotsquad.com/tournament/brackets.asp - you'll see I need to display certain records based on some filters but with that layout you cannot do repeat regions or even nested.
------------- I am dedicated to being addicted.
|
Replies:
Posted By: Mart
Date Posted: 24 August 2003 at 1:38pm
|
SELECT TOP 16 * FROM FIELD; - I think thats what you want...
Mart.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 5:25pm
|
SELECT TOP 16 * FROM FIELD
That will only pull the top 16 records out of a select field right? Well, I need each of those records pulled to be created as a FIELD ITEM.
Like when you do:
SELECT COUNT(tournid) AS totaltournid or something.
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 5:26pm
|
Basically, if you look at that reference page above you'll see what I'm trying to do.
I need to pull the top 16 records out each as a field item so I can individually place one by one in the table on the far left. Then create another recordset that will pull out only 8 records which I will place one by one, etc. Get it?
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 6:34pm
|
Basically, I need to collect the content of recordset into an array so I can individually place values from the recordset.
How do I do all that?
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 24 August 2003 at 6:56pm
You can place a recordset into an array by using the GetRows Method
arrayName = RecordSetName.GetRows
it will create a two dimensional array with your recordset data.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 8:26pm
|
I think I have it working for now ... I was trying to use a basic array and kept getting a Type Mismatch.
Thanks for steering me in the right direction!
<-- newb
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 8:33pm
|
If the value I am displaying is null, how can I make it say something like "None" ...
I tried If isnull(arrRound1(3,1) then but that doesn't work?
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 24 August 2003 at 8:42pm
IsNull should work. Try
IsNull (arrRound(3,1))
note the additional ')' to close the ISNull Function
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:03pm
|
Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 1]'
<% If IsNull (arrRound1(3,1)) Then arrRound1(3,1) = "None" Response.Write(arrRound1) End If%>
------------- I am dedicated to being addicted.
|
Posted By: b_bonnett
Date Posted: 24 August 2003 at 9:07pm
|
Thats because you used Response.Write(arrRound1), not Response.Write(arrRound1(3,1)).
Blair
------------- Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:09pm
|
I changed it to this right after posting that:
If (arrRound1(3,1)) = "" Then arrRound1(3,1) = "None" Else Response.Write(arrRound1(3,1)) End If
Still does not work ...
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:10pm
I get an object out of range error ...
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 24 August 2003 at 9:15pm
How many rows are in the recordset? How many columns?
The first number in the array represents the column you want to display. The second number the row. Remember that arrays begin with 0, so the first olumn in the first row would be arrayName(0,0).
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: b_bonnett
Date Posted: 24 August 2003 at 9:18pm
|
Comment out that code and put the following in there:
Response.Write "Array Dimensions: " & UBound(arrRound1) & " x " & UBound(arrRound1, 2) |
Then post what it says here.
Blair
------------- Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:18pm
|
Their is only one row in the recordset and five columns. In literal the column I want to use is number four which means it's number three here.
So displaying arrRound1(3,0) works fine because their is one row.
Displaying arrRound1(3,1) does not because there is no "second" row.
So I want to put some IF statements to display something else so the page continues.
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:19pm
|
Array Dimensions: 4 x 0
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:22pm
|
Here is the full recordset code and the GetRow.
<% Dim rsround1__MMColParam rsround1__MMColParam = "1" If (Request("MM_EmptyValue") <> "") Then rsround1__MMColParam = Request("MM_EmptyValue") End If %> <% Dim rsround1__MMColParam2 rsround1__MMColParam2 = "1" If (Request.QueryString("tournid") <> "") Then rsround1__MMColParam2 = Request.QueryString("tournid") End If %>
<% Dim rsround1 Dim rsround1_numRows
Dim arrRound1
Set rsround1 = Server.CreateObject("ADODB.Recordset") rsround1.ActiveConnection = MM_db_data_conn_STRING rsround1.Source = "SELECT TOP 16 * FROM TBL_TOURNAMENTBRACKETS WHERE bracketposition = " + Replace(rsround1__MMColParam, "'", "''") + " AND tournid = " + Replace(rsround1__MMColParam2, "'", "''") + " ORDER BY tournbracketsid ASC" rsround1.CursorType = 0 rsround1.CursorLocation = 2 rsround1.LockType = 1 rsround1.Open()
rsround1_numRows = 0
arrRound1 = rsround1.GetRows %> |
------------- I am dedicated to being addicted.
|
Posted By: b_bonnett
Date Posted: 24 August 2003 at 9:23pm
|
That means the entry in the array you are trying to reference does not exist. The columns go from 0 to 4 (i.e. five entries) and there is one row (0). So you can't reference the (non-existent) second row, which is what you are trying to do, hence the error.
Blair
------------- Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:24pm
|
Exactly - I know and understand this ... I want to say if the second-sixteen does not exist, display this instead.
How?
------------- I am dedicated to being addicted.
|
Posted By: b_bonnett
Date Posted: 24 August 2003 at 9:31pm
|
Try using the following:
If UBound(arrRound1, 2) > 0 Then ...Display Stuff From Array... Else ...Message Saying Whatever... End If |
Basically, if there are two rows, then UBound(arrRound1, 2) will equal one - I've used > 0 so that it will also display if there are more than 2. If there is only one row, then your message saying "No data in the second row", or whatever the message is, will be displayed.
Blair
------------- Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch
|
Posted By: ljamal
Date Posted: 24 August 2003 at 9:41pm
Use Ubound(arrRound1,2) to determine if the row is available. If Ubound(arrRound1,2) is less than the row you are seeking then you do not have values to display in the row. Remember that the even Ubound begins counting at 0 so an array with one row will have an Upper Bound (UBound) equal to zero (0) not one (1). An array will no rows should produce an error with Ubound, I believe.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 9:42pm
|
hmm - how do i incorporate this for 16 rows?
if you look at the link on the first page, each gray line will have response.write(arrRound(3,0)) (0-15)
see what im saying?
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 24 August 2003 at 10:03pm
I'm assuming that you have 5 recordsets (one for each round) and each record set should have half the number of records as the previous so use a For loop and mod
For i = 0 to Ubound(arrRound1,0)
Response.Write arrRound1(0,i)
if i mod 2 = 0 then
Response.Write arrRound2(0,CLng(i/2))
end if
if i mod 4 = 0 then
Response.Write arrRound3(0,CLng(i/4))
end if
if i mod 8 = 0 then
Response.Write arrRound4(0,CLng(i/8))
end if
if i mod 16 = 0 then
Response.Write arrRound5(0,CLng(i/16))
end if
Next
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 10:05pm
|
I'm a complete newb to this so I have no idea what that means to do ... it just confused me more?
Can you explain it a little better please?
And yes, you were exactly right. They key thing is I need to display "teamname" on specific table rows for each round.
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 24 August 2003 at 10:11pm
|
I'm sure I have to do something to that piece of code but I put that into my page, as is and I still get an out of range error?
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 25 August 2003 at 5:41am
The code above assumes that you have all five recordsets stored into arrays, so you will need those arrays. Second, it assumes that there are at least one row in each of the arrays.
The for statement creates a loop that will loop through each row in the first array (arrRound1). The mod function provides you with the remainder from dividing 2 numbers. 4 mod 3 is 1. 2 mod 2 is 0. 10 mod 3 is 1. You only want to display arrRound2 once for every 2 arrRound1, when i mod 2 = 0 arrRound2 will be displayed. Because the array rows in arrRound2 are half the value of the corresponding rows in arrRound1 you divide i by 2. Because there is no remainder i/2 should be a whole number, so the CLng isn't really needed, but I added it anyway to insure that you have an integer. The above then follows for each additional array with every array having exactly half the records of the previous one thus the you go from 2 to 4 to 8 to 16.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 25 August 2003 at 8:52am
|
The problem with that is possible that their is not ALWAYS going to be exactly half of what is in the previous array.
Reason being, a team may progress to the next bracket faster then another. Which means their could only be 1 team in the round 2 (arrRound2) for awhile.
Get it?
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 25 August 2003 at 9:53am
Then you will need to check to see that there is a row available and then check to see if the team listed in the row goes along with the team in the pairing.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 25 August 2003 at 11:04am
how do i check to see if their is a row?
------------- I am dedicated to being addicted.
|
Posted By: ljamal
Date Posted: 25 August 2003 at 11:09am
If you have an array then it must have a least one row. You can not use the GetRow method when there are no rows to retrieve.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Mikeap
Date Posted: 25 August 2003 at 12:41pm
|
... ok so use a normal array method
I tried that originally but kept getting a type mismatch, I guess i'll retry it
I appreciate the help!
I hope to getting it working soon! :)
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 26 August 2003 at 1:27pm
|
How about ....?
arrRound = rsRound1.GetRows
strRound1 = (Cstr(arrRound1(3,0))
Then later on <% Response.Write(strRound1) %>
Is that the proper logic?
------------- I am dedicated to being addicted.
|
Posted By: Mikeap
Date Posted: 26 August 2003 at 1:30pm
|
Then you could do
if strRound1 = "" then strRound1 = "None" end if
------------- I am dedicated to being addicted.
|
Posted By: b_bonnett
Date Posted: 26 August 2003 at 5:56pm
Mikeap wrote:
How about ....?
arrRound = rsRound1.GetRows
strRound1 = (Cstr(arrRound1(3,0))
Then later on <% Response.Write(strRound1) %>
Is that the proper logic? |
Sorta, but if there is no rows, you'll get an error with GetRows.
Try:
blnRound1 = False If Not rsRound1.EOF Then arrRound1 = rsRound1.GetRows blnRound1 = True End If
If blnRound1 Then strRound1 = arrRound1(3,0) Else strRound1 = "None" End If |
Blair
------------- Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch
|
Posted By: Mikeap
Date Posted: 26 August 2003 at 7:42pm
|
I got it working ... I could not get it to loop or do a counter either ... just would not work.
So I manually assigned array values to variables and did it that way.
It's setup so even if the recordset is empty that it will just show none.
------------- I am dedicated to being addicted.
|
|