Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

xp_SendMail Padded spaces in text file

Posted on 2002-06-10
4
Medium Priority
?
267 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 200 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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

715 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