Filter data table

Asked

Viewed 75 times

0

How to select only part of a table record?

Source data:

"brt_qsr01:NT"

and I intended it to return only qsr01

I’m doing so, but then I can’t remove the data on the left

  SELECT left([coluna], CHARINDEX(':', [coluna]) -1 ) FROM [dbo].[tabela]   

2 answers

0

For this particular case, you could do so:

SELECT substring( nome_coluna, 5, 5 ) FROM tabela

But if the positions are different from record to record, you need to apply a smart rule. If so, post more information so we can help you.

0

Thanks for the tips

Solved 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 I want: qsr01

Browser other questions tagged

You are not signed in. Login or sign up in order to post.