Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Null

Status
Not open for further replies.

mdr227

Programmer
Nov 17, 2000
114
0
0
US
I am trying to pre-determine a sort order for an insert statement I am using. I create a recordset with a statement such as this:

set rs1=conn.execute("select max(sort) maxsort from tblTest where category = ' & request.form("txtCategory") & "'")

I think have a variable that I am trying to increment by one to find the new sort order. Something like varsort = rs1("maxsort") + 1. The problem is that if there is no match on my select statement I am not able to set the varsort = 1 because the addition won't work when the recordset is empty.
 
if you are getting a NULL returned from your query, you could either just check for that special case, or instead tell SQL to return some value in place of the NULL by using the ISNULL() function,

SELECT ISNULL(Max(sort), 0) as maxsort

this would return 0 in place of a null, which would be the cause of your addition problems.

Another way might might be to just check the value before trying to do any addition on it, such as

Set rs = myConn.Execute(...)
If rs("maxsort") = NULL Then
' handle appropriately or use default value
Else
' handle normally
End If


regards,
-f!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top