Why do I enter a data in my BD when I enter a space at the beginning?

1

I have a problem with the maintenance of a system, when inserting a new data I put a space at the beginning when it is saved. Example: entering a

asked by Celeste Guerra 29.11.2018 в 01:50
source

1 answer

1
  

From SQL Server you can help with the following functions:

  • LTRIM() What helps me to eliminate spaces at the beginning of a string
  • RTRIM() Which helps me to eliminate spaces at the end of a string
  • You can both work mixed and use them as in the following example

     INSERT INTO tableName(columnaUno) VALUES(LTRIM(RTRIM(valorUno)));
    

    So that although I write the following:

    INSERT INTO tableName(columnaUno)
    values 
    (LTRIM(RTRIM('      daniel  '))), (' alfredo');
    

    The final result will be

    select * from tableName;

    columnaUno
    daniel  
     alfredo    
    pedro   
    
      

    Daniel although he declared himself with spaces on both sides, they were   deleted by the 2 functions, as the Alfredo register was added a   space but no function was passed, said space at the beginning   he kept

        
    answered by 29.11.2018 в 02:18