Query Search Specific Word in a Field - SQL Server

Asked

Viewed 4,491 times

-1

Is there a function that I can only find the data of a field ?

I’m only trying to get from Expiration until 2019, I have several lines with this validity information, and they don’t appear in the same position.

inserir a descrição da imagem aqui

  • Will the "validity" text always exist in the Description column? The date is always in the dd/mm/yyyy format ?

2 answers

0

If the text follows this pattern you can do a search with the LIKE:

SELECT t.*
  FROM tabela t
 WHERE t.descricao LIKE '%, validade %2019%, dívida%';

-1


I am only trying to get from the Validity until 2019

Try something like

-- código #1 v3
...
case when charindex (', validade ', DescricaoAndamento) > 0
          then substring (DescricaoAndamento, 
                          charindex (', validade ', DescricaoAndamento) +2, 
                          19)
     else NULL end
...

The code snippet above initially searches where it starts the text ", validity ".

It was considered that the expiry date will always contain 10 characters.

Browser other questions tagged

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