Solved

xp_SendMail Padded spaces in text file

Posted on 2002-06-10
4
263 Views
Last Modified: 2008-02-01
All,
The following SQL is run in an overnight job, the purpose to run a SQL query and email the results in a text file to a valid email address..



use Master
exec xp_sendmail @recipients = "MADMARLIN@HOME.co.uk",
                    @Message = "Please Find Enclosed The Information Pack Requests",
           @separator  = ",",
           @Query = "USE DB1 Select Forename, surname, age From TABLE1",
              @subject = "TEST ONLY",
           @attach_results = 'TRUE',
           @no_header ='True',
           @width = 1000


The process runs fine but the fields within the text file show as follows

john       ,smith      ,21  ,

Is there anyway I can stop this padding of spaces???
and so the text file would read as
john,smith,21,

The fields are all varchars with different lengths which I think may be part of the problem. The additional spaces dont sem to be stored in the DB field so I'm assuming its looking at the field max length and padding accordingly..

Any ideas??

Madmarlin

PS this question is also repeated in other topic areas but points will be given for only one answer across all areas..
0
Comment
Question by:Madmarlin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:lozzamoore
ID: 7066611
Try using ltrim and rtrim functions:

exec xp_sendmail @recipients = "MADMARLIN@HOME.co.uk",
                   @Message = "Please Find Enclosed The Information Pack Requests",
          @separator  = ",",
          @Query = "USE DB1 Select ltrim(rtrim(Forename), ltrim(rtrim(surname), ltrim(rtrim(age) From TABLE1",
             @subject = "TEST ONLY",
          @attach_results = 'TRUE',
          @no_header ='True',
          @width = 1000
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7066617
RTrim, ltrim and cast functions doen't work :-(

My comments In VB:
http://www.experts-exchange.com/questions/Q_20309720.html
0
 
LVL 7

Accepted Solution

by:
lozzamoore earned 50 total points
ID: 7066633
How about:

exec xp_sendmail @recipients = "MADMARLIN@HOME.co.uk",
                  @Message = "Please Find Enclosed The Information Pack Requests",
         @separator  = ",",
         @Query = "USE DB1 Select Forename + ', ' + surname + ', ' + age From
TABLE1",
            @subject = "TEST ONLY",
         @attach_results = 'TRUE',
         @no_header ='True',
         @width = 1000

With cast if age is not char, (which is should be!)
Cheers,
0
 
LVL 1

Author Comment

by:Madmarlin
ID: 7266937
Did find this out myself but since you also suggested this then you can have the points
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question