May 3, 2004 at 1:05 pm
In a procedure where I'm building a string from a select. How can I remove the trailing Tab before the end of the string? For example
String builder:
Select @concatstring = @concatstring+column_val+char(9)
From table where<where condition>
End result of a select:
'2344 doe jane 293844 '
Want to see this:
'2344 doe jane 293844'
May 3, 2004 at 4:16 pm
After your statement for the concatenation do something like the following...
SET @concatstring = LEFT(@concatstring , LEN(@concatstring ) - LEN(char(9)))
Gary Johnson
Microsoft Natural Language Group
DBA, Sr. DB Engineer
This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.
May 3, 2004 at 4:23 pm
That did it. Thank you.
demicoq
May 3, 2004 at 4:34 pm
Just a note: The SQL Server Function RTRIM can be used for this exact purpose. The syntax is RTRIM(@concatstring).
May 4, 2004 at 12:31 pm
Sorry Peter but if you have Latin1_General_Bin as your default database collation that is not the case. I just ran the following to test it.
DECLARE @vTest nvarchar(255)
SET @vTest = 'string with tab at end.' + char(9)
SELECT '|' + @vTest + '|', '|' + RTRIM(@vTest) + '|'
,'|' + LEFT(@vTest , LEN(@vTest ) - LEN(char(9))) + '|'
I wish that RTRIM Worked that way though!
Gary Johnson
Microsoft Natural Language Group
DBA, Sr. DB Engineer
This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.
May 4, 2004 at 12:48 pm
My Bad. You are absolutely right!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply