sql server - Adding Trailing Zeros to an int field in SQL -
in process of resequencing web items, trying append 4 zeros on end of each item sequence number. try not work, seems automatically remove trailing zeros because of formatting. int field. thing got work 1 item test doing replace such as:
update sacatalogitem set itm_seq = replace(itm_seq, '8021', '80210000') itm_id = '13' , ctg_id = '917'
i have tried using cursor replace , strips trailing zeros when executing this:
declare @seq int declare @id int declare @ctg int declare cur cursor select a.itm_seq, a.itm_id, a.ctg_id sacatalogitem join saitem b on b.itm_id = a.itm_id a.cat_id = '307' , a.itm_id = '13' , a.ctg_id = '917' open cur fetch next cur @seq,@id,@ctg while (@@fetch_status=0) begin update sacatalogitem set itm_seq = replace(itm_seq, @seq, @seq + '0000') itm_id = @id , ctg_id = @ctg update saitem set itm_import_action = 'p' itm_id = @id fetch next cur @seq,@id,@ctg end close cur deallocate cur
this fails me:
update sacatalogitem set itm_seq = itm_seq + '0000' itm_id = '13' , ctg_id = '917'
any appreciated small frustrating problem.
if integer field, multipy 10000.
update sacatalogitem set itm_seq = itm_seq * 10000 itm_id = '13' , ctg_id = '917'
Comments
Post a Comment