In this stackoverflow question, the accepted answer involves repeating the same code fragments several times. In my experience, many people tend to reduce this by encapsulating code fragments in different ways, for various reasons,
- Maintaining health (fewer places to change)
- Readability (read the code once, then it is "alias" every subsequent time)
- etc, etc
Using the code in a related question, how would you decide to reduce the repetition of identical code fragments? Or do you just leave it as it is?
(Do not use alternative logic, but stick to using REPLACE, etc., just by changing the presentaiton of the same logic.)
Select Case
When CharIndex('.', Replace(URL, 'www.','')) > 0 then
Left(Replace(URL, 'www.',''), CharIndex('.',Replace(URL, 'www.',''))-1)
Else
Replace(URL, 'www.','')
End as [CleanURL]
From dbo.YourTable
( , .)
, , .
:
- ?
:
- ?