Solved

xp_SendMail Padded spaces in text file

Posted on 2002-06-10
4
257 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
  • 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 142

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how the fundamental information of how to create a table.
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…

772 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