Error in sql server

Asked

Viewed 92 times

2

No sql como faço para fazer um select com espaço e sem espaços?

That is, when I have a pass of the genus '123456' and '123456', the last one with space happens to be done in the query and I have '123456 ' in the bd should not show me field no visa that has a space and my parameter is '123456'

slq password= '&%$#"! ' this is the pass I have in sql that is equal to 123456, it happens that if you put 1234567 in it and should not enter it. 1234567 corresponds to '&%$#"! ' encoded.

Got it?

3 answers

4


You can use % to indicate that you don’t care what comes after him. Note: To use this operator you need to use like

Examples are: Search all lines where campo begins with 1234

SELECT * FROM tabela WHERE campo like '1234%'

Search all lines where campo contains 2345

SELECT * FROM tabela WHERE campo like '%2345%'

Search all lines where campo ends with 456

SELECT * FROM tabela WHERE campo like '%456'

To authenticate user and password, the correct is to take the password entered by the user, apply the encryption on this password and compare the result with the encryption that is already saved in the bank.

  • but if you have a space '123456 'in the login he enters and the pass is '123456'

  • @user2964140 User authentication selects and password in the database should compare if the password entered is EXACTLY EQUAL to the password stored in the bank, you should not disregard spaces or anything of the kind... Perhaps your question should be asked differently...

  • but the password is encrypted and can contain spaces

  • @user2964140 You must take the password entered by the user, apply the same encryption on this password and compare if the result is EXACTLY EQUAL to the one in the bank, this way you will not need to disregard anything, it is just an exact comparison.

  • yes already solved the problem with like 'asphalt%'

  • @user2964140 If this answer helped you, please mark it as the answer to your question.

  • 1

    is already marked

Show 2 more comments

2

Compare the value with the column using trim() or its variants(ltrim() and rtrim()).

SELECT * FROM tabela WHERE trim(campo) = trim(valor)
  • 1

    SELECT * FROM USERS Where EMAIL ='[email protected]' AND PASSWORD =LTRIM('123456 ') in the bd the field has only 123456

  • the question is that the database can have tbm blank spaces in the genus '123456 8' or even a space.... why Trim does not work

  • In the case of value '123456' compared to the value of the base '12345 ' Trim() resolves, now '12345 6' not much to do.

  • the point is that I have an encritptada pass with xor 23 ...123456 corresponds to this '&%$#"! ' happens that if you enter login 1234567 it enters the table because 7 is a space and should not enter, it happens that tbm can have spaces the word pass. Similarly if the pass is '&%$#"! ' and put 123456 and enter tbm and should not enter because the characters are not equal

  • @user2964140, edit your question and add these details may get easier for other people to answer, puts the Sqlserver tag as well.

0

To prevent the values with end space return, you can make use of the function REPLACE.

select * 
from TABELA
where replace(COLUNA, ' ', '_') = replace('123456', ' ', '_')

Here is an example from rextester

Browser other questions tagged

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