sql server - How to extract strings between two special different characters in TSQL -
i using code following question: how extract strings between 2 special characters in tsql
declare @c varchar(100) set @c = 'microsoft.systemcenter.useractionmanager:servername_1.domain.net;servername_2.domain.net' select substring(@c, charindex(':', @c) + 1, len(@c) - charindex('.', @c) - charindex(':', @c))
current result:
servername_1.domain.net;servername_2.
i want search column/string , extract string starting @ ':'
, going first '.'
.
the result trying is: servername_1
the caveat server name vary in length.
also, when try run following query:
select substring(column_name, charindex(':', column_name) + 1, len(column_name) - charindex(':', column_name) - charindex(':', column_name)) [dbo].[servernametable]
i following error:
msg 537, level 16, state 3, line 1 invalid length parameter passed left or substring function.
many in advance.
this replace , including first :
using stuff
. uses same result find first .
, substring
stuff
result first .
declare @c varchar(100) set @c = 'microsoft.systemcenter.useractionmanager:servername_1.domain.net;servername_2.domain.net' select substring(stuff(@c, 1, charindex(':',@c), ''), 0, charindex('.', stuff(@c, 1, charindex(':',@c), '')))
Comments
Post a Comment