Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql statement

Posted on 2006-07-09
10
Medium Priority
?
243 Views
Last Modified: 2010-04-30
mysql 5.0


correct sql statemnt to change a column from yes to no
0
Comment
Question by:thenone
10 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17070551
>correct sql statemnt to change a column from yes to no

put in here the correct name of the table and the columns:

UPDATE `yourtable` SET `thecolumn` = 'no' WHERE `keyfield` = <keyvalue> AND `thecolumn` = 'yes'

0
 
LVL 8

Author Comment

by:thenone
ID: 17070591
thanks angel
0
 
LVL 8

Author Comment

by:thenone
ID: 17070592
and if I do not have a primary key?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17070642
>and if I do not have a primary key?
how do you identify the row to update then?
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17070660
UPDATE `yourtable` SET `thecolumn` = 'no' WHERE `thecolumn` = 'yes'

This will update everything - regardless of the id
0
 
LVL 8

Author Comment

by:thenone
ID: 17073422
and if I was doing it with a recordset?
0
 
LVL 8

Author Comment

by:thenone
ID: 17076756
ok so if I have a recordset where it is rs.open"select * from table1 where column=no"

then when I am looping through my records how can I have the recordset be able to change that column one at a time from no to yes.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17077065
rs.open "select * from table1 where column=no"
while not rs.eof
   rs.fields("column").value = "yes"
   rs.update
   rs.movenext
wend
rs.close
0
 
LVL 8

Author Comment

by:thenone
ID: 17077115
so just this?

rs.fields("column").value = "yes"

ok thanks.
0
 
LVL 9

Accepted Solution

by:
lojk earned 1000 total points
ID: 17080983
you would generally never do such a thing... It causes all sorts of record locking issues for starters not to mention the fact that it is *slow*

you would already have dimmed a connection to connect your rs anyway, so why not just do..

dim MyConn as new adodb.connection
myconn=whatever
myconn.execute ("UPDATE `yourtable` SET `thecolumn` = 'no' WHERE `keyfield` = <keyvalue> AND `thecolumn` = 'yes' ")

as angel had already posted?


also, if your DB is access and this is a boolean field rather than text (as it should be) you may actually need to do...

rs.fields("column").value = true


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question