473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem in updating a table...

43
hi
i am having a situation where i have to update a whole column and set one value true and rest false For example If the table have two columns Name and Status respectively...
Name Status
aTrue
bFalse
cFalse

and if status of b is set to true now then all other status should be false

aFalse
bTrue
cFalse

is this possible with only runnign one query or i have to run two query one for updating all to False and then second to update a particular record to True
any suggestions....
Thanks in advance
Mar 4 '08 #1
5 1027
amitpatel66
2,367 Expert 2GB
hi
i am having a situation where i have to update a whole column and set one value true and rest false For example If the table have two columns Name and Status respectively...
Name Status
aTrue
bFalse
cFalse

and if status of b is set to true now then all other status should be false

aFalse
bTrue
cFalse

is this possible with only runnign one query or i have to run two query one for updating all to False and then second to update a particular record to True
any suggestions....
Thanks in advance
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE table1 SET status = (CASE WHEN name = 'a' THEN TRUE ELSE FALSE END)
  3.  
  4.  
Mar 4 '08 #2
bravo
43
thanks a lot amit it worked perfectly....
Mar 4 '08 #3
amitpatel66
2,367 Expert 2GB
You are welcome :) .
Mar 4 '08 #4
ronverdonk
4,258 Expert 4TB
Try this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE table1 SET status = (CASE WHEN name = 'a' THEN TRUE ELSE FALSE END)
That is a neat one amitpatel6!

Ronald
Mar 4 '08 #5
amitpatel66
2,367 Expert 2GB
That is a neat one amitpatel6!

Ronald
Thanks Ron :) .
I will take that!! :)
Mar 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sean Utt | last post by:
Table "grps" Column | Type | Modifiers -------------+-----------------------------+-------------------------------- --------------------- grpsid ...
2
by: Ray | last post by:
I have a list of about 20,000 rows that I am updating. I loop through each row in my program and basically do the following (1) select * from TABLE where SID= for update /*lock the row*/ (2)...
1
by: William Bradley | last post by:
At the moment I am having a problem with relationships and updating tables. The following is a production run. Table1 -- MainFormTable1 -- Basic Table Record Table2 ----SubFormTable2 --...
3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
1
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a...
1
by: Mark | last post by:
I'm having a problem updating recordsin an Access DB table. I can update other tables in this db with no problem, and I can dreate new record in all of the tables (including this one.)> But I can't...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
1
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and...
3
by: shark | last post by:
Hi all. i am facing a deadlock problem .i have included the -t1204 and -T3605 trace flags and have got the following o/p pu tin sqls server logs. 2006-06-01 17:49:21.84 spid4 2006-06-01...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.