Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Remove space between 2 columns

Author  Topic 

deogaurav
Starting Member

2 Posts

Posted - 2010-09-24 : 04:03:35
I have created a script that would create a txt file.
I am facing an issue in which between any 2 columns I am getting an extra space. I do not want that in output.
Eg

Scenario 1 ( Column Names : NAME and AGE) ( Coumn Length 5 and 3)

NAME AGE
JOHN 42
TROYD 34
KATHY 40
RAM 35

Scenario 2 ( Column Names : NAME and AGE) ( Coumn Length 5 and 3)

NAME AGE
JOHN 42
TROYD34
KATHY40
RAM 35

I need output in second format while it is coming in first.
Please let me know how to achieve this.

Thanks
Gaurav

rohitvishwakarma
Posting Yak Master

232 Posts

Posted - 2010-09-24 : 04:09:43
use RTRIM(NAME)+LTRIM(AGE)
Go to Top of Page

deogaurav
Starting Member

2 Posts

Posted - 2010-09-24 : 05:12:04
quote:
Originally posted by rohitvishwakarma

use RTRIM(NAME)+LTRIM(AGE)



What RTRIM LTRIM does it it removes all trainling or leading spaces..But I want spaces that are equal to my (column length-data length)

For e.g in given table Name column is of 5 bytes then RAM name should succeeded by 2 spaces and then AGE should come. Also if any column is null it should contain spaces = full column length.

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-24 : 05:22:27
declare @Name varchar(5), @Age varchar(3)
set @Name = 'RAM'
set @Age = '35'

select
left(isnull(ltrim(rtrim(@Name)),space(5))+space(5),5)+
left(isnull(ltrim(rtrim(@Age)),space(3))+space(3),3)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -