Say Col1 is your column with your data to trucate. Try this:
select substring(rtrim(cast(col1) as varchar(255)),3,datalength(rtrim(cast(col1) as varchar(255)))-3) as newcol1 from table
That would get what you need I believe even if it is an integer datatype. If it is character then just drop the casting and you should have it. Let me know if it doesn't work.
Sorry,
The starting position should be 4 and not 3. The datalength function would allow you to handle any character length while the rtrim will remove any padded spaces to the right. The modified code you have will work for you. One other thing you might want to do is CAST the substring as an integer so you have the same datatype that was input for output. Just a thought. Glad to see it worked for you.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.