Filter table data

0

How to select only part of the record from a table?

Source data:

"brt_qsr01:NT"

and I intended it to return only qsr01

I'm doing this, but then I can not remove the data on the left

  SELECT left([coluna], CHARINDEX(':', [coluna]) -1 ) FROM [dbo].[tabela]   
    
asked by anonymous 19.01.2018 / 17:06

2 answers

0

For this specific case, you could do this:

SELECT substring( nome_coluna, 5, 5 ) FROM tabela

But if the positions differ from registration to registration, you need to apply a smart rule. If so, please provide more information so we can help.

    
19.01.2018 / 17:14
0

Thanks for the tips

Resolved the problem

DECLARE @teste varchar(100)
SET     @teste = '"brt_qsr01:NT"' 


select SUBSTRING(@teste,CHARINDEX('_',@teste)+1,CHARINDEX(':',@teste)-CHARINDEX('_',@teste)-1) 

Returns only the string that I want: qsr01

    
21.01.2018 / 19:56