sql server 2008 - Append number to front of string with leading 0 -


how correctly replace first character 'm'? suppose have patient_id_nonnum = 'm001', , want 1001 result.

update [himc_i2b2_lz-prod].[dbo].[i2b2_src_biometrics] set patient_id = convert(numeric(22,0),'1' + convert(nvarchar(50),patient_id)) substring(patient_id_nonnum, 1, 1) = 'm' 

edit:

update [himc_i2b2_lz-prod].[dbo].[i2b2_src_medication] set patient_id = convert(numeric(22,0),convert(nvarchar(50),'1') + convert(nvarchar(50),substring(patient_id_nonnum, 2, len(patient_id_nonnum)))) substring(patient_id_nonnum, 1, 1) = 'm' 

i find stuff() (an overlooked function) , left() little more readable, others may disagree:

update [himc_i2b2_lz-prod].[dbo].[i2b2_src_biometrics] set patient_id = cast(stuff(patient_id_nonnum, 1, 1, '1') numeric(22,0)) left(patient_id_nonnum, 1) = 'm' 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -