Update data with spaces in sql server

3

I have a database, with a couple of tables in which I have stored many records that have been brought from another database.

My big drawback is that the data has passed with spaces, before the actual data, it seems that sql server will take this space as a character, since when it is consulted it does not appear. My question is: Is there any way to update all this data and remove this space?

I add image to complement my problem

the field in which the problem is presented is code1

    
asked by Andrex_11 11.04.2018 в 23:45
source

1 answer

4

about your concern you can solve it using t-sql functions like LTRIM and RTRIM in the following way:

UPDATE TuTabla SET Codigo1 = LTRIM(RTRIM(Codigo1));

When performing this update process will remove the blank spaces that exist in the columns.

Another possibility is that you make a replace in your query so that when the query is executed, replace the fields with a wildcard such as a "-" instead of the blank spaces, in this way you would no longer have blank spaces in your query, also about the query remember the like command with its wildcards "% tuValor%" if it is a string what you are comparing.

I hope you find it useful, greetings.

    
answered by 11.04.2018 / 23:54
source