September 17, 2010 at 10:26 am
Hello,
Can anyone please let me know, how to add as many white spaces as the length of text in select statement. Please see the following example:
Col1 Col2
---- ----
ABC (I want to count Col1 value ABC , which is 3 and then append it to the Col1 text)
Thanks.
September 17, 2010 at 11:03 am
Sounds like a use for the replicate function.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 17, 2010 at 11:15 am
SPACE can do it for you
SELECT SPACE( LEN( Col1)) + Col1 from <your table>
And as Wayne suggested, u can use REPLICATE as well.. like:
SELECT REPLICATE(' ' , LEN(col1)) + Col1 from <your table>
~Edit : Initially suggested STUFF ,which, of course is a dumb-*** suggestion.. sorry folks.. now changed it to SPACE function..
September 20, 2010 at 1:36 pm
Thank you guys. It worked fine. 😉
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply