In the Outcomes table, transform names of the ships containing more than one space, as follows:
replace all characters between the first and the last spaces (excluding these spaces) by symbols of an asterisk (*).
The number of asterisks must be equal to number of replaced characters.
Result set: the name of a ship, the transformed name of the ship
Solution:
select
ship, substring(ship, 1, charindex(‘ ‘, ship, 1)) +
replicate(‘*’, DATALENGTH(ship) – charindex(‘ ‘, ship, 1) – charindex(‘ ‘, reverse(ship), 1)) + substring(ship, DATALENGTH(ship) – charindex(‘ ‘, reverse(ship), 1) + 1, DATALENGTH(ship)) last from outcomes
where
charindex(‘ ‘, ship, charindex(‘ ‘ , ship, 1) + 1) > 0