Search function for Sql Server

Asked

Viewed 63 times

0

I wonder if it has a function or if it could be done with a select, search by e-mail field of a table. Example:

select PPESSOA.EMAIL from PPESSOA where PPESSOA.NOME like 
'ABNER FONTOURA C,RÊA'
'ADAILTON PEREIRA DE SOUZA' 
'ADALBERTO ROMUALDO PEREIRA HENRIQUE',
'ADELINA MARIA GOMES SCHETTINI ' ,
'ADELINA MARIA VASCONCELOS DE OLIVEIRA ' ,
'ADELLE KARINNE NASCIMENTO SILVA' ,
'ADEMIR VIEIRA DE MELO GARCIA' ,
'ADENILSON OLIVEIRA ANDRADE' ,
'ADENILSON ROBERTO JOSE PEREIRA' ,
'ADILLO LUIZ FARIA MEZZOMO' ,
'ADILSON DA SILVA ALVES ',
'ADILSON MARCOS MENDES ' ,
'ADMILSO ANTONIO DA SILVA ' ,
'ADMILSON SILVA FINTELMAN ' ,
'ADRIANA ALMEIDA DE SOUZA ' ,
'ADRIANA APARECIDA ALVES DE FREITAS ' ,
'ADRIANA APARECIDA CAETANO DA SILVA ' ,

and has over 3000 records..

How I do?

  • These 3000 records are in another table?

  • 1

    Of more information, why these guys will be selected, what they have in comun...

  • I’m sorry I couldn’t tell you, but they’re all on the same table.. i selected this way: select PPESSOA.EMAIL from PPESSOA Where PPESSOA.NAME IN ('name1', 'Nome2',...) so there are spaces between the quotes and Sql is not returning the result due to these spaces between the name and the quotes; 'name1 ',

  • @Felipe why are you searching by name? What table structure?

  • Use locate and replace, replace the espaço+apostrofe by just one apostrofe

1 answer

1

Use LTRIM and RTRIM at each occurrence to avoid spaces as follows:

select PPESSOA.EMAIL from PPESSOA where PPESSOA.NOME in ( 
ltrim(rtrim('ABNER FONTOURA C,RÊA')),
ltrim(rtrim('ADAILTON PEREIRA DE SOUZA')),
ltrim(rtrim('ADALBERTO ROMUALDO PEREIRA HENRIQUE')),
...
);
  • I tried to use Ltrim, only I would have to do this for each name, so it would take a lot of time. Thank you very much. I managed to create a replacement similar to what Lucasmotta indicated. Thank you Lucas, I did otherwise, using word.. It took a lot of work, but I just did it. .

Browser other questions tagged

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