| |

VerySource

 Forgot password?
 Register
Search
View: 698|Reply: 4

What should I do to modify some values ​​in a field in the SQL data table?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-4 23:40:01
| Show all posts |Read mode
There is a DDD field in the data table ABC. There are a large number of data records in this field. For example, the data in it is 1,2,3,4. I want to change all 4 in this field to 1, and 3 to 2. What should I do? Thank you
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-5 00:57:01
| Show all posts
--try

update ABC SET DDD = CASE WHEN DDD = 4 THEN 1 WHEN DDD = 3 THEN 2 END
WHERE DDD IN (4, 3)
Reply

Use magic Report

1

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-5 11:45:01
| Show all posts
update abc
set ddd = replace (ddd, '4', '1')
where charindex ('4', ddd) <> 0

update abc
set ddd = replace (ddd, '3', '2')
where charindex ('3', ddd) <> 0
Reply

Use magic Report

0

Threads

30

Posts

25.00

Credits

Newbie

Rank: 1

Credits
25.00

 China

Post time: 2020-1-7 00:09:02
| Show all posts
UPDATE ABC SET DDD = REPLACE (REPLACE (DPLACE, '4', '1'), '3', '2')
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-11 10:09:02
| Show all posts
update ABC
set DDD =
 case when DDD = '4' then '1'
      when DDD = '3' then '2'
      else DDD end
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list