简体   繁体   中英

sql server query for update rows which are multiple of 2

I've a table with many rows. I've to meet the requirement that those rows which are multiple of 2 should only be updated. eg

update [DBO].[ZZZ_FKP_FEMALE_FULLNAME_TBL]
set remarks = 'multiple of TWO'
--- update only those rows which are multiple of 2.
--- where ID = MULTIPLE OF 2
here ID column is primary key with auto increment

How can I solve this?

You can use modulo as @jarlh said, here is the code:

UPDATE T SET T.remarks = 'multiple of TWO'
FROM [DBO].[ZZZ_FKP_FEMALE_FULLNAME_TBL] AS T
WHERE ID % 2 = 0
update [DBO].[ZZZ_FKP_FEMALE_FULLNAME_TBL] set remarks = 'multiple of TWO'where ID % 2 = 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM