I am working on a SQL query that reads from a SQLServer database to produce an extract file. One of the requirements to remove the leading zeroes from a particular field, which is a simple VARCHAR(10)
field. So, for example, if the field contains '00001A', the SELECT statement needs to return the data as '1A'.
Is there a way in SQL to easily remove the leading zeroes in this way? I know there is an RTRIM
function, but this seems only to remove spaces.
You can use this:
you can try this
SELECT REPLACE(columnname,'0','') FROM table
This should do.
If you want the query to return a 0 instead of a string of zeroes or any other value for that matter you can turn this into a case statement like this:
I borrowed from ideas above. This is neither fast nor elegant. but it is accurate.
CASE
END