How to Update following Data [Resolved]

Posted by Jayakumars under Sql Server on 1/18/2018 | Points: 10 | Views : 389 | Status : [Member] [MVP] | Replies : 1
Hi,

How to Update Following Data

create table tempEmp
(
Id int primary key identity(1,1),
Empname nvarchar(20),
EmpCode nvarchar(100)
)

select * from tempEmp

insert into tempEmp values ('John',1234567890)
insert into tempEmp values ('Joseph',78045678901)
insert into tempEmp values ('esJohn',987234567890)

/* after 3 characters only i need update like this (But Remaining digits Must be equal) */
/*outoput i need like this */

1 John 1231111111
2 Joseph 78011111111
3 esJohn 987111111111

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Rajnilari2015 on: 1/18/2018 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
@Jayakumar,
Here you go

create table tempEmp
(
Id int primary key identity(1,1),
Empname nvarchar(20),
EmpCode nvarchar(100)
)
insert into tempEmp values ('John',1234567890)
insert into tempEmp values ('Joseph',78045678901)
insert into tempEmp values ('esJohn',987234567890)

--select
-- *,ValueToUpdate =left(EmpCode,3) +replicate('1',len(EmpCode)-3)
--from tempEmp

update tempEmp
set EmpCode = left(EmpCode,3) +replicate('1',len(EmpCode)-3)

select *
from tempEmp

drop table tempEmp


Result
-----------

Id	Empname	EmpCode
1 John 1231111111
2 Joseph 78011111111
3 esJohn 987111111111


--
Thanks & Regards,
RNA Team

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response