Hey PRA,
Please refer below query.
SQL
DECLARE @INFO AS TABLE (Id INT, NAME VARCHAR(15))
INSERT INTO @INFO VALUES (1,'Orange')
INSERT INTO @INFO VALUES (2,'Onion')
INSERT INTO @INFO VALUES (3,'Potatoes')
INSERT INTO @INFO VALUES (4,'Melon')
SELECT Id,CASE
WHEN name LIKE 'o%' THEN SUBSTRING(name, 2, LEN(name)-1)
WHEN name LIKE '%o' THEN LEFT(name, LEN(name)-1)
ELSE name
END Name
FROM @INFO
Output
Id |
Name |
1 |
range |
2 |
nion |
3 |
Potatoes |
4 |
Melon |