Error in sql server

2

In sql how do I make a select with space and no spaces?

That is, when I have a pass of the genre '123456' and '123456', the last one with space happens that if I do in the query and I have '123456' in the bd I should not show any field that has a space and the My parameter is '123456'

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

Did you notice?

    
asked by anonymous 24.09.2015 / 19:02

3 answers

4

You can use % to indicate that you do not care what comes after it. Note: To use this operator you must use like

Examples: Find all rows where campo starts with 1234

SELECT * FROM tabela WHERE campo like '1234%'

Search for all rows where campo contains 2345

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

Search for all rows where campo ends with 456

SELECT * FROM tabela WHERE campo like '%456'

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

    
24.09.2015 / 19:22
2

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

SELECT * FROM tabela WHERE trim(campo) = trim(valor)
    
24.09.2015 / 19:09
0

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

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

Follow the example on rextester

    
24.09.2015 / 19:31