Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 can anyone simplfy this sql code?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 13 April 2001 :  17:50:21  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
this code runs on every single page on my site and was wondering if someone could think of a better way to write it?


strActiveUsersCheckOutTime = DATEADD("s", -1000, Now)

if strDBNTUserName = "" then
strActiveUserName = "n/a"
else
strActiveUserName = strDBNTUserName
end if

strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME, " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN "
strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'"
set rs = my_Conn.Execute (strSQL)

if rs.eof or rs.bof then
'// THEY ARE NOT IN THE DATABASE SO LETS ADD THEM


strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('"
strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')"
my_Conn.Execute (strSQL)
else
'// THEY ARE IN THE DATABASE SO LETS UPDATE THERE STUFF

'// FIRST LETS MAKE SURE THEY ARE NOT SUPOSED TO BE TIMED OUT
strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN "
strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' "
strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "' "
set rs2 = my_Conn.Execute (strSQL)

if rs2.eof or rs2.bof then
'// NOW LETS UPDATE THEM SINCE THEY ARE NOT SUPOSED TO BE TIMED OUT
strSQL = "UPDATE " & strMemberTablePrefix & "Active_Users SET " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN='" & Now & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME='" & strActiveUserName & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_ID='" & strDBNTUserID & "' WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'"
my_Conn.Execute (strSQL)
else
'// DELETE THEM
strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' "
strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & Now & "' "
my_Conn.Execute (strSQL)

strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('"
strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')"
my_Conn.Execute (strSQL)

end if
end if

'// LETS DELETE ALL INACTIVE USERS
strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users WHERE A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "'"
my_Conn.Execute (strSQL)


Brad

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 13 April 2001 :  18:31:40  Show Profile  Visit HuwR's Homepage
try this

strActiveUsersCheckOutTime = DATEADD("s", -1000, Now)

if strDBNTUserName = "" then
strActiveUserName = "n/a"
else
strActiveUserName = strDBNTUserName
end if

strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME, " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN "
strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'"
set rs = my_Conn.Execute (strSQL)

if rs.eof or rs.bof then
'// THEY ARE NOT IN THE DATABASE SO LETS ADD THEM
strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('"
strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')"
my_Conn.Execute (strSQL)
else
'// THEY ARE IN THE DATABASE SO LETS UPDATE THERE STUFF

'// FIRST LETS MAKE SURE THEY ARE NOT SUPOSED TO BE TIMED OUT

if rs("A_LAST_CHECKIN") < strActiveUsersCheckOutTime
'// NOW LETS UPDATE THEM SINCE THEY ARE NOT SUPOSED TO BE TIMED OUT
strSQL = "UPDATE " & strMemberTablePrefix & "Active_Users SET " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN='" & Now & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME='" & strActiveUserName & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_ID='" & strDBNTUserID & "' WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'"
my_Conn.Execute (strSQL)
else
'// DELETE THEM
strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' "
strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & Now & "' "
my_Conn.Execute (strSQL)
end if
end if

'// LETS DELETE ALL INACTIVE USERS
strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users WHERE A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "'"
my_Conn.Execute (strSQL)


Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 13 April 2001 :  18:39:47  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
oh thanks huwr, i thought i was probley missing something

Brad
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 13 April 2001 :  18:48:51  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
quote:


strActiveUsersCheckOutTime = DATEADD("s", -1000, Now)

if strDBNTUserName = "" then
strActiveUserName = "n/a"
else
strActiveUserName = strDBNTUserName
end if

strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME, " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN "
strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'"
set rs = my_Conn.Execute (strSQL)

if rs.eof or rs.bof then
'// THEY ARE NOT IN THE DATABASE SO LETS ADD THEM
strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('"
strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')"
my_Conn.Execute (strSQL)
else
'// THEY ARE IN THE DATABASE SO LETS UPDATE THERE STUFF

'// FIRST LETS MAKE SURE THEY ARE NOT SUPOSED TO BE TIMED OUT

if rs("A_LAST_CHECKIN") < strActiveUsersCheckOutTime THEN
'// NOW LETS UPDATE THEM SINCE THEY ARE NOT SUPOSED TO BE TIMED OUT
strSQL = "UPDATE " & strMemberTablePrefix & "Active_Users SET " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN='" & Now & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME='" & strActiveUserName & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_ID='" & strDBNTUserID & "' WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'"
my_Conn.Execute (strSQL)
else
'// DELETE THEM
strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users "
strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' "
strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & Now & "' "
my_Conn.Execute (strSQL)
end if
end if

'// LETS DELETE ALL INACTIVE USERS
strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users WHERE A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "'"
my_Conn.Execute (strSQL)




oh you were so close to being perfect i know you probley dont care but ill just post what was left off incase for some odd reason someone would like to use this code.

Brad
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07