sql - How to update database column values in a single command(no CASE/SWITCH)? -


lets have table name swap-table.

    *input table*      id  name    type     ------------------      1   name1        2   name2    b     3   name3    b   

i want write single command update table.the output table be

   **output table**      id  name    type     ------------------      1   name1    b     2   name2        3   name3    

condition: no case/switch

i offer "cute" way transformation, rather i'd allow (or recommend) in production code:

declare @t table (id int not null,name varchar(17) not null,type varchar(3) not null) insert @t(id,name,type) values (1,'name1','a'), (2,'name2','b'), (3,'name3','b') update @t set type = char(195-ascii(type))  select * @t 

produces:

id          name              type ----------- ----------------- ---- 1           name1             b 2           name2             3           name3             

(different database products may have different ways transform from/to ascii codes , table variables)


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -