Solved

xp_SendMail Padded spaces in text file

Posted on 2002-06-10
4
255 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
Comment Utility
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]
Comment Utility
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
Comment Utility
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
Comment Utility
Did find this out myself but since you also suggested this then you can have the points
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Restore Script - Syntax Error 8 70
SQL JOIN 6 31
while loop in html mail format 5 32
search for a string in all tables 4 15
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now