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.
| 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.EgScenario 1 ( Column Names : NAME and AGE) ( Coumn Length 5 and 3)NAME AGEJOHN 42TROYD 34KATHY 40RAM 35Scenario 2 ( Column Names : NAME and AGE) ( Coumn Length 5 and 3)NAME AGEJOHN 42TROYD34KATHY40RAM 35I need output in second format while it is coming in first.Please let me know how to achieve this.ThanksGaurav |
|
|
rohitvishwakarma
Posting Yak Master
232 Posts |
Posted - 2010-09-24 : 04:09:43
|
| use RTRIM(NAME)+LTRIM(AGE) |
 |
|
|
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. |
 |
|
|
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'selectleft(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. |
 |
|
|
|
|
|