Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2008-08-27 : 02:20:34
|
| I have a table with a bit column, in some cases that value is true and in some false, can I in one single update change the ones that are true to false and vice versa? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-27 : 02:24:17
|
yes. use CASE WHEN to do it KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2008-08-27 : 02:39:49
|
| Ahhh, thanks alot! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-27 : 02:43:29
|
[code]DECLARE @Sample TABLE (r INT IDENTITY(100, 10), b BIT)INSERT @SampleSELECT 0 UNION ALLSELECT 1SELECT *FROM @SampleUPDATE @SampleSET b = 1 - bSELECT *FROM @Sample[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-27 : 03:11:21
|
[code]DECLARE @Sample TABLE (r INT IDENTITY(100, 10), b BIT)INSERT @SampleSELECT 0 UNION ALLSELECT 1SELECT *FROM @SampleUPDATE @SampleSET b = b ^ 1SELECT *FROM @Sample[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
joe.inom
Starting Member
9 Posts |
Posted - 2008-08-27 : 04:22:58
|
| yes you can do that , but keep in mind that the codecs are to be perfect.San Diego Home Insurancejoe Alexender |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2008-08-27 : 04:34:34
|
| Hi PesoI see that your sugestion works just fine, but can you explain the "SET b = b ^ 1" part? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-27 : 04:45:11
|
| its exclusive OR operator.have a look at BOL for detailsms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/f38f0ad4-46d0-40ea-9851-0f928fda5293.htm |
 |
|
|
|
|
|