Sunday, 15 February 2015

sql server - Substring select string between two caracters -



sql server - Substring select string between two caracters -

the next code

declare @text varchar(max) set @text='[dim company].[company].[23]' select substring(@text, charindex('[dim company].[company].[', @text) , charindex(']',@text) - charindex('[dim company].[company].[', @text) + len(']'))

returns [dim company]. expecting homecoming integer between lastly [] -- in case 23. how can desired field?

if know it's last, why not reverse string, find value between first pair of brackets, reverse result?

much easier nesting charindex calls.

sql-server

No comments:

Post a Comment