Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 What causes this error?

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2005-06-04 : 17:03:41
I have a simple ASP script that connects to a SQL 2k DB and writes out the info in a table. I am using a do while loop to print out the information but the odd thing is that I am getting an error '80020009' when I use this code:

<%do while trim(objrs("min_level")) > 69 and trim(objrs("min_level")) < 76%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>

but if I use this code the error goes away:
<%do while trim(objrs("min_level")) > 69 and trim(objrs("min_level")) < 75%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>


At current the highest number in min_level is 75 but why is it when I move the check above that number it errors?

--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.

nr
SQLTeam MVY

12543 Posts

Posted - 2005-06-04 : 17:21:16
Because you are reading beyond the end of the resultset. The first one stops when it gets a 75. The second when it gets a read error.

change to
do while trim(objrs("min_level")) > 69 and trim(objrs("min_level")) < 75% and not objrs.eof


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2005-06-04 : 18:54:13
I changed to code to

<%do while trim(objrs("min_level")) > 69 and trim(objrs("min_level")) < 80 and not objrs.eof%>

but I still get the error.

Edit:
Looking over my question I guess I should add that I need to include the results that have a min_level of 75 and leave room for min_level to include records of upto 80.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-06-04 : 23:35:43
oops - that will try to evaluate values on the read as well as the eof flag.
you need something like

do while not objrs.eof
if minlevel > 69 and minlevel < 80
......
endif
objrs.movenext
loop

But why not just get the rows in the resultset that you need

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2005-06-05 : 03:03:04
quote:
Originally posted by nr

oops - that will try to evaluate values on the read as well as the eof flag.
you need something like

do while not objrs.eof
if minlevel > 69 and minlevel < 80
......
endif
objrs.movenext
loop

But why not just get the rows in the resultset that you need

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.



I do not know if that will work. Earlyer in the script I have the same code only for lower level sets. If you want I can post the entire script but it is around 400 lines of code.

--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-06-05 : 03:54:28
What happens of you run the SQL statement in query analyzer ? Is there anything in the data that looks right ?

Why are you trimming a recordset value then comparing it to an integer ?


Damian
Ita erat quando hic adveni.
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2005-06-05 : 04:21:25
quote:
Originally posted by Merkin

What happens of you run the SQL statement in query analyzer ? Is there anything in the data that looks right ?

Why are you trimming a recordset value then comparing it to an integer ?


Damian
Ita erat quando hic adveni.


The SQL statment I use is fine, it pulls all the records I need and sorts them by min_level. I am triming and compairing to an intager because it is habbit to trim all data retrived form my DB I could just as easly remove the trim command.

I think everyone will undrstand what my situation is better if I post the entire if code black that has all the problem code in it:

<%if weapon = "Invalid Choice" then%>
<p>I am sorry, but there are no weapon classes of the type you put in</p>
<%else%>
<p>The table below lists all the <%=weapon%> in Final Fantasy XI. As a quick referance also listed is the weapons level, damage amount, delay rating, and what job classes can use them, and it's type (Normal, Rare, Exlusive, or Rare/Exlusive). If you want more detailed information on the weapon just click on it's name.</p>
<table border="1" class="normal" align="center" width="100%">
<tr class="header">
<td>Weapon</td>
<td>Level</td>
<td>DMG</td>
<td>Delay</td>
<td>Class</td>
<td>Type</td>
</tr>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 1-9</td>
</tr>
<%do while trim(objrs("min_level")) < 10%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 10-19</td>
</tr>
<%do while trim(objrs("min_level")) > 9 and trim(objrs("min_level")) < 20%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 20-29</td>
</tr>
<%do while trim(objrs("min_level")) > 19 and trim(objrs("min_level")) < 30%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 30-39</td>
</tr>
<%do while trim(objrs("min_level")) > 29 and trim(objrs("min_level")) < 40%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 40-49</td>
</tr>
<%do while trim(objrs("min_level")) > 39 and trim(objrs("min_level")) < 50%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 50-59</td>
</tr>
<%do while trim(objrs("min_level")) > 49 and trim(objrs("min_level")) < 60%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 60-69</td>
</tr>
<%do while trim(objrs("min_level")) > 59 and trim(objrs("min_level")) < 70%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px; text-decoration: underlinded">Level 70-75</td>
</tr>
<%do while trim(objrs("min_level")) > 69 and trim(objrs("min_level")) < 80 and not objrs.eof%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%objrs.movenext
loop%>
</table>
<p class="note">Is this information wrong/out of date or are you getting different results? Then please <a href="http://www.finalfantasyinfo.com/contact.html">contact us</a> and let us know.</p>
<%end if%>


--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.

<edit> to fix too-wide layout </edit>
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-06-05 : 06:46:32
The problem is with the lat one.
When it reads past the end of the file the eof flag will be set on but as fields from the resultset are accessed in the same statement as the check it will give an error.

You can replace the last loop with the code I gave above or


do while not objrs.eof
if lvl > x and lvl < x
endif
if lvl > x and lvl < x
endif
if lvl > x and lvl < x
endif
objrs.movenext
loop




==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2005-06-05 : 09:56:06
quote:
Originally posted by nr

The problem is with the lat one.
When it reads past the end of the file the eof flag will be set on but as fields from the resultset are accessed in the same statement as the check it will give an error.

You can replace the last loop with the code I gave above or


do while not objrs.eof
if lvl > x and lvl < x
endif
if lvl > x and lvl < x
endif
if lvl > x and lvl < x
endif
objrs.movenext
loop




==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.


Repalceing the code with what you gave me earlyer results in a differant error.

Microsoft VBScript compilation error '800a0400'

Expected statement

/ffxi/weapons/weapon.asp, line 352

end if

Which is basicly saying it expected the loop (or the movenext command) before the end if. I can not add an end if after each loop since the loops are not controlled by an if statment. If you look at my code you will see I first check to see if the weapon is an invalid choice or not. If it is valid then I go though and print all the weapons. I can not modify this to be 8 differant if statments without screwing the hole page up.

--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-06-05 : 10:13:41
You need some "Then" after the ifs. I think Nigel was giving you an example, for you to implement.

You've been working on this game for about 3 years now, how is it coming ?


Damian
Ita erat quando hic adveni.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-06-05 : 11:34:42
YOu are eseentially grouping by "Level" and showing a header for each new level; you shouldn't duplicate all of your code to do this, you should use a loop and write your SQL to help you out. Just add a "LevelGroup" calculation to your SELECT (something probably as convert(int, Level/10)) and keep track of when that value changes; when it does, in your loop, print your heading for that group.

If you need to be sure you get at least 1 row per group of Levels, then you can use a table of LevelGroups:

MinLevel, MaxLevel, LevelGroup
1,9,'1-9'
10,19,'10-19'
20,29,'20-29'
..etc...

then left outer join from LevelGroups to your data:

select
LG.LevelGroup, a.*
from
LevelGroups LG
left outer join
YourTable a
on
a.Level between LG.MinLevel and LG.MaxLevel
order by
LG.MinLevel, ... etc ...


In your ASP code, you would then simply loop through your data like this:


<%
dim LastLevelGroup
LastLevelGroup = ''

while not rs.EOF
if LastLevelGroup <> rs!LevelGroup then
%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px;
text-decoration: underlinded">Level <%=rs!LevelGroup%></td>
</tr>
<%
LastLevelGroup = rs!LevelGroup
end if
%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%
rs.movenext
loop
%>


and that's it! Much shorter, easier to maintain, more efficeint, and also more flexible. If you find yourself copying and pasting code in your programs, chances are you should either figure out a way to loop instead, or break that code out into a function.

If you have lots of pages like this to write, you might find my "ASP Report Class" code very helpful to handle things like group headers and footer very easily:

http://weblogs.sqlteam.com/jeffs/articles/526.aspx

- Jeff
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2005-06-05 : 16:25:42
quote:
Originally posted by Merkin

You need some "Then" after the ifs. I think Nigel was giving you an example, for you to implement.

You've been working on this game for about 3 years now, how is it coming ?


Damian
Ita erat quando hic adveni.


I came to understand what Nigel was talking about earler today. As for the game, that is actualy a differant site then the one this script is on. That game was finished a while ago and ran great with about 50% automation. But the game has come to a point where the players agreed a restart was needed so I am not working on a new version with better automation. THis scipt is for an information site, http://www.finalfantasyinfo.com/ , on the Final Fantasy game series.

quote:
Originally posted by jsmith8858

YOu are eseentially grouping by "Level" and showing a header for each new level; you shouldn't duplicate all of your code to do this, you should use a loop and write your SQL to help you out. Just add a "LevelGroup" calculation to your SELECT (something probably as convert(int, Level/10)) and keep track of when that value changes; when it does, in your loop, print your heading for that group.

If you need to be sure you get at least 1 row per group of Levels, then you can use a table of LevelGroups:

MinLevel, MaxLevel, LevelGroup
1,9,'1-9'
10,19,'10-19'
20,29,'20-29'
..etc...

then left outer join from LevelGroups to your data:

select
LG.LevelGroup, a.*
from
LevelGroups LG
left outer join
YourTable a
on
a.Level between LG.MinLevel and LG.MaxLevel
order by
LG.MinLevel, ... etc ...


In your ASP code, you would then simply loop through your data like this:


<%
dim LastLevelGroup
LastLevelGroup = ''

while not rs.EOF
if LastLevelGroup <> rs!LevelGroup then
%>
<tr>
<td colspan="6" style="text-align: center; font-size: 18px;
text-decoration: underlinded">Level <%=rs!LevelGroup%></td>
</tr>
<%
LastLevelGroup = rs!LevelGroup
end if
%>
<tr>
<td><%=trim(objrs("weapon"))%></td>
<td><%=trim(objrs("min_level"))%></td>
<td><%=trim(objrs("damage"))%></td>
<td><%=trim(objrs("deley"))%></td>
<td><%=trim(objrs("weapon_class"))%></td>
<td><%=trim(objrs("type"))%></td>
</tr>
<%
rs.movenext
loop
%>


and that's it! Much shorter, easier to maintain, more efficeint, and also more flexible. If you find yourself copying and pasting code in your programs, chances are you should either figure out a way to loop instead, or break that code out into a function.

If you have lots of pages like this to write, you might find my "ASP Report Class" code very helpful to handle things like group headers and footer very easily:

http://weblogs.sqlteam.com/jeffs/articles/526.aspx

- Jeff



Ok, I think I understand what your getting at here. But can you explain a few things to me? I know very little about joins and do not understand most of the syntac in the join you gave. Can you explain what the a.* and the other "a" listing in the join are? Also what is <%=rs!LevelGroup%>? As for the template it was acutaly an old file that had all the old infor for one set of weapons hand typed, then after doing all that I relized I was stupid and should be using a DB so I just hacked the old file into what you saw, I really did not think about shortingin it, but i will.

--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.
Go to Top of Page
   

- Advertisement -