Here is the question:
+--------------+
Ships |
+--------------+
Duke of north |
---------------+
Prince of Wales|
---------------+
Baltic |
---------------+
I need to 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.
for example: "Duke of North" must be replaced as "Duke ** North", I managed to cut the "of" from "Duke of North" but am really stuck with the replacement part, can any one give me some ideas, am learning SQL in MS SQL Server 2005, please help. I dont need the exact answer just give me some ideas,
select
case when charindex(' ',ship,(charindex(' ',ship,1))+1) > 0
then substring(ship,(charindex(' ',ship,1))+1,((charindex(' ',ship,(charindex(' ',ship,1))+1)) - (charindex(' ',ship,1))))
end "Replace"
from
outcomes
This is not a homework question, am learning SQL.