Skip to content

Instantly share code, notes, and snippets.

@timgaunt
Created December 3, 2021 14:53
Show Gist options
  • Save timgaunt/fe72cebc022d5b2db04d52403d2731c5 to your computer and use it in GitHub Desktop.
Save timgaunt/fe72cebc022d5b2db04d52403d2731c5 to your computer and use it in GitHub Desktop.
Strip domain from url
select
substring(Url,
(case when charindex('//', Url)= 0 then 1 else CHARINDEX('//', Url) + 2 end),
case
when charindex('/', Url, charindex('//', Url) + 2) > 0 then charindex('/', Url, charindex('//', Url) + 2) - (case when charindex('//', Url)= 0 then 1 else charindex('//', Url) + 2 end)
when charindex('?', Url, charindex('//', Url) + 2) > 0 then charindex('?', Url, charindex('//', Url) + 2) - (case when charindex('//', Url)= 0 then 1 else charindex('//', Url) + 2 end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment