Click here to Skip to main content
15,891,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one table plan_scheme that table having column headcode single digit i want to add zero in that column if single digit means

2, it's like a 02,05,08 likewise 32, 34, two digit as it is
how to write query .
Posted

SQL
UPDATE plan_scheme SET headcode  =
(CASE WHEN LEN(headcode ) = 1 THEN RIGHT('0' + CONVERT(VARCHAR, headcode ), 2)
ELSE headcode  END);
select * from plan_scheme
 
Share this answer
 
v2
try this.. :)

SQL
select case len(headcode) when 1 then '0'+convert(varchar,headcode) else convert(varchar,headcode) end as value from headcode
 
Share this answer
 
SQL
CREATE TABLE plan_scheme
(
headcode varchar(5)
)

insert into plan_scheme values('01')

SELECT * from plan_scheme



[Edit member="Tadit"]
Added pre tags.
[/Edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900