I am trying to use a T-SQL REPLACE statement to replace the middle 4 numbers under the DepartmentID column....
I understand the simple way of changing one set of DepartmentID numbers I want to be able to change all middle numbers under DepartmentID
SELECT REPLACE (DepartmentID,'000701280918','000799990918') AS DepartmentID
FROM Employees
Objective Select all the employees, replace 4 middle numbers with 9999 in DepartmentID:
---4-----4-----4
0007 0128 0918
4 char to the left
4 char to the right
4 char in the middle
Table: Employees
First Column in Table: EmployeeID
Column: DepartmentID
000701280918
000701782662
000702220442
000702118362
000702108487
000702109473
000702033600
000702275707
How would I write the statement
Thank You for your assistance
Check out the stuff function:
update YourTable
set DepartmentId = stuff(DepartmentId, 5, 4, '9999')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With