SQL Server 2012 Random string from a list

前端 未结 5 660
暖寄归人
暖寄归人 2021-01-01 18:20

say I have 3 values, Bill, Steve, Jack. and I want to randomly update a table with those values, eg

Update contacts set firstname = (\'Bill\',\'Steve\',\'Jack\') whe

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 19:00

    Here's some love using choose

    with cte as (
       select *, (ABS(CHECKSUM(NewId())) % 3) + 1 as n
       from contacts
       where city = 'NY'
    )
    update cte
    set firstname = choose(n, 'Bill','Steve','Jack')
    

提交回复
热议问题