0

I have 2 bit columns in a table active and suspended The active column already contains values but the suspended column still null

How can I fill the suspended field with values that is opposite of active?

I was stuck in this code..

 Declare @suspended bit;

 --some conditions

 Update Users_mock
 Set Suspended = @Suspended;
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
Emmanuel Gabion
  • 425
  • 1
  • 9
  • 20

5 Answers5

2

A simple case statement should work:

Update userM
Set suspend = case active when 0 then 1 else 0 end
dani herrera
  • 48,760
  • 8
  • 117
  • 177
1

You may check this Update sql bit field in database.

It says, **Bits in SQL Server are always stored as 1 or 0 in a bitmap. **

You may use a where, if-else or case to update the column.

Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
1

select abs(CONVERT(int,@suspended)-1)

Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
1

Try this:

update Users_mock
set Suspended = case when active=1 THEN 0
else 1
end
4b0
  • 21,981
  • 30
  • 95
  • 142
0

Please try:

Update Users_mock
Set Suspended = 1-Active;
TechDo
  • 18,398
  • 3
  • 51
  • 64