Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 05:17 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Conditional SQL

I am trying to get a conditional UPDATE SQL statement to update an Access database but, every time, it updates the second SQL statement and not the first.?

Here is the SQL statement:

strSQL7 = "SELECT * FROM tblDevices WHERE DeviceID_ID = '" & Session("DeviceName") & "'"

objARec.Open strSQL7, strConnDataData, adOpenForwardOnly, adLockOptimistic

If objARec("DeviceStatus")="Out of Service" then
    strSQL2 = "UPDATE tblDevices SET DeviceStatus='Out of Service' WHERE DeviceID_ID = '" & Session("DeviceName") & "'"
    objAConn.Execute strSQL2

Else
    strSQL2 = "UPDATE tblDevices SET DeviceStatus='Needs-Service' WHERE DeviceID_ID = '" & Session("DeviceName") & "'"
    objAConn.Execute strSQL2

end if


Any ideas? Thanks.
 
Old March 3rd, 2004, 05:26 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Are you sure objARec("DeviceStatus") has any value at all? Try doing...

    response.write objARec("DeviceStatus")

above your if/else and see what you get.

 
Old March 3rd, 2004, 05:32 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In this particular case yes, because I have actually set ("DeviceStatus") to 'Out of Service' in the full script. This particular part for the conditional SQL is just a part of the whole script, which is long but I will post it if need be.
 
Old March 4th, 2004, 01:53 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

That's fine if you have a variable called device status in your script, but you are querying it out of the recordset as well and that is the value I was mentioning. How about trying something like this...

rs = server.createobject("adodb.recordset")
sql = "select * from tblDevices where DeviceId_Id = '" & Session("DeviceName") & "'"
rs.open sql, strConnDataData, 3, 3
if not rs.eof then
    if rs("DeviceStatus") = "Out of Service" then
        rs("DeviceStatus") = "Out of Service"
    else
        rs("DeviceStatus") = "Needs Service"
    end if
        rs.update
end if

QUESTION?
If DeviceStatus is already "Out of Service" then why are you trying to update it as "Out of Service"?






Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional css sbkumar CSS Cascading Style Sheets 3 July 15th, 2008 04:32 PM
Conditional transformation vvenk XSLT 3 July 10th, 2008 09:09 AM
Need help with conditional sql statement MarkGT Classic ASP Basics 11 May 6th, 2008 08:41 PM
conditional IF roy_mm Reporting Services 0 October 30th, 2006 07:52 AM
Conditional IF statement iloveoatmeal Classic ASP Basics 5 July 20th, 2005 08:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.