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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 using SQL server we need to replace true to false

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2006-04-06 : 13:19:42
Using SQL server we need to replace true to false and false to true in the same flag field(boolean) using the single stm(update)

Kristen
Test

22859 Posts

Posted - 2006-04-06 : 13:24:15
Something like this you mean?

UPDATE MyTable
SET MyColumn = CASE WHEN MyColumn = true THEN flase ELSE true END

Kristen
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2006-04-06 : 13:25:45
Well, let's start with the fact that SQL Server does not have a data type known as boolean. Perhaps you are dealing with a BIT datatype which is your closest approximation. In that case, I'll assume you want to switch 1 to 0 and 0 to 1 all in one statement. Perhaps something like this will work:

UPDATE mytable SET
myfield = CASE
WHEN myfield = 1 THEN 0
WHEN myfield = 0 THEN 1
ELSE myfield -- account for the possibility that BIT can be NULL unless your field is defined as NOT NULL
END




Damn that Kristen guy!

---------------------------
EmeraldCityDomains.com
Go to Top of Page
   

- Advertisement -