I'm trying to select the first part of a string with a delimiter that doesn't always exist. I have the below SUBSTRING
function that works great when the delimiter is present, but doesn't return anything when it isn't i.e. the query below
SELECT SUBSTRING(sc.location +'/',0, CHARINDEX('/', sc.location)) FROM sc
yields Tower #1
for the value Tower #1/Room #3
, but NULL
if the input is just Tower #5
Is there a way to return the full string if the delimiter does not exist?
SUBSTRING(sc.location +'/',0, CHARINDEX('/', sc.location + '/'))
– Salutary