How to do WHERE with an incomplete name to find the record that in the bank is with the full name?

Asked

Viewed 71 times

0

Hello, I need to get the system to email the registered person on a form as the engineer in charge. Then I need to make an SQL that looks for the email from the name. So far ok. If the person type exactly the person’s name as it is in the bank, all right. But the field is a normal input, not a Suggest, there is no verification if the entered name actually exists. So I wanted to query, if the user registers "João Silva" in the form, the SQL search found in the database the record "João Guilherme da Silva". The way it is now, if the user only type "Silva", he thinks "João Guilherme da Silva", but if you type "João Silva", he finds nothing. Can you help me, please?

    SELECT user_seq, user_name, user_email, user_elogin 
    FROM tabela_usuarios
    WHERE user_name LIKE < cfqueryparam 
    cfsqltype="cf_sql_varchar" 
    value="%#arguments.engineerName#%"

Obs, use coldfusion :)

  • Important you EDITAR this question, explaining it clearly, objectively and directly, emphasizing the difficulty found. Furthermore, provide us with a Minimum, complete and verifiable example problem, along with its attempt to resolve. What’s more, I suggest reading the Stack Overflow Survival Guide in English to better understand the functioning of the platform, avoiding further frustrations.

  • Are you sure you can’t search for the id? If you use LIKE it can bring none or more of a result. Taking into account that you need to send the email to the existing user, to whom would you send it? To everyone? Your code would have an inconsistency as it could send an email to the incorrect user.

2 answers

1

A solution is in the "form" to separate the name inputado in an array with several names for example

SO-AND-SO

array {FULANO, BELTRANO, TAL}

eliminate the OF

make a dynamic sql with the array

(NOME LIKE '%FULANO%BELTRANO%TAL%')

Assuming the order OR

( (NOME LIKE '%FULANO%') OR
  (NOME LIKE '%BELTRANO%') OR
  (NOME LIKE '%TAL%') ) 

without taking into account the order

Details of the implementation depend on the DBMS and Front-End used , here only the general idea.

Note : Beware of SQL Injection

-1

try:

SELECT * FROM `users` WHERE `name` LIKE '%ped%';

use the % at the beginning and end of the searched text.

  • When thinking about answering a certain question, read How to write a good answer?. Also, use good arguments objectively demonstrating cordiality.

Browser other questions tagged

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