Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2004, 05:17 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old March 3rd, 2004, 05:26 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Minneapolis, MN, USA.
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.

Reply With Quote
  #3 (permalink)  
Old March 3rd, 2004, 05:32 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
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.
Reply With Quote
  #4 (permalink)  
Old March 4th, 2004, 01:53 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Minneapolis, MN, USA.
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"?

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:32 AM.


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