sql - How to update a field with a varchar + incrementing int -


im trying update values in table have unique values in format 'unknown' + 0001 next 1 'unknown' + 0002. im runnign trouble when trying update field.

 declare @idtest varchar(15)      set @idtest = ''      update table1      set @idtest = id = convert(int,'unknown'+ cast(@idtest + 1  varchar(15)))      id null or ltrim(rtrim(id )) = ''     go  

any suggestions great. can use sql supported 2008 r2.

update:

with tempupdatetable (           select t1.*,                  row_number() on (order (select null)) seqnum           table1 t1           id null or ltrim(rtrim(id)) = ''         )         update tempupdatetable         set id= 'unknown' + right('000' + cast(seqnum varchar(255)), 4); 

use row_number() , updatable cte:

with toupdate (       select t1.*,              row_number() on (order (select null)) seqnum       table1       id null or ltrim(trim(id )) = ''      ) update toupdate     set id = 'unknown' + right('00000000', cast(seqnum varchar(255)), 8); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -