sql server - Database update SQL -


suppose have following table

membertable

id (1 letter + 5 digits) | name | type 

and have following records

a00000 | peter |  b00001 | amy   | b  c00002 | susan | ... 

now need update id base on follow criteria:

  1. all start 00-
  2. then comes 2 digits base on member type
  3. then add original id except 1st letter

member type digits mapping

a -> 00  b -> 01  c -> 02  

there following data suppose have after update

00-0000000 | peter |  00-0100001 | amy   | b  00-0000002 | susan | 

suppose mapping document reference, ie. not have table store mapping details.

any suggested update statement? help.

you didn't specify dbms, mysql answer:

update membertable set id = concat('00-',                 case type                     when 'a' '00'                     when 'b' '01'                     when 'c' '02'                 end,                 substr(id, 2)) 

the syntax other databases different, basic idea should same.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -