I have data which has leading and trailing spaces in the string. when storing that data in database I want to trim the space in query itself before storing into DB.
Normal spaces are trimming properly with RTRIM and LTRIM function but if a string contains tab space,its not trimming the tab space from the input string.
Can anyone help me to get the string with trimmed with tab space from leading and trailing.
Replace the ASCII code for tab (9):
replace(@str, char(9), '')
To only remove the outer tabs, first change them to something that won't exist in your data (I use a series of four spaces in this example), then rtrim/ltrim, then convert that same sequence back to tabs:
replace(ltrim(rtrim(replace(@str, char(9), ' '))),' ', char(9));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With