473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Formatting @query results using xp_sendmail

I know formatting should be handled in the client app and not in SQL Server
but this is the situation I must develop in so any help would be
appreciated.

I'm running the following in Query Analyzer

USE Pubs
DECLARE @MessageSubject VARCHAR(50)
SELECT @MessageSubject = 'Report'
EXEC master.dbo.xp_sendmail 'm*@mine.com',
@query = 'SELECT au_fname, au_lname from pubs.dbo.authors',
@subject = @MessageSubject

The results in my email look like:

au_fname au_lname
------------------- ----------------------------------------
Abraham Bennet
Reginald Blotchet-Halls
Cheryl Carson

I would like the results to be like:

First Name: Abraham
Last Name: Bennet

First Name: Reginald
Last Name: Blotchet-Halls

First Name: Cheryl
Last Name: Carson

Thanks

Jul 20 '05 #1
2 6393

"Terri" <Te***@spamaway.com> wrote in message
news:c0**********@reader2.nmix.net...
I know formatting should be handled in the client app and not in SQL Server but this is the situation I must develop in so any help would be
appreciated.

I'm running the following in Query Analyzer

USE Pubs
DECLARE @MessageSubject VARCHAR(50)
SELECT @MessageSubject = 'Report'
EXEC master.dbo.xp_sendmail 'm*@mine.com',
@query = 'SELECT au_fname, au_lname from pubs.dbo.authors',
@subject = @MessageSubject

The results in my email look like:

au_fname au_lname
------------------- ----------------------------------------
Abraham Bennet
Reginald Blotchet-Halls
Cheryl Carson

I would like the results to be like:

First Name: Abraham
Last Name: Bennet

First Name: Reginald
Last Name: Blotchet-Halls

First Name: Cheryl
Last Name: Carson

Thanks


See CHAR() in Books Online - you could try something like this:

select
'First Name: ' + au_fname + char(13) + 'Last Name: ' + au_lname +
char(13) + char(13)
from
pubs.dbo.authors

Simon
Jul 20 '05 #2

"Simon Hayes" <sq*@hayes.ch> wrote in message
news:40**********@news.bluewin.ch...

See CHAR() in Books Online - you could try something like this:

select
'First Name: ' + au_fname + char(13) + 'Last Name: ' + au_lname +
char(13) + char(13)
from
pubs.dbo.authors


This works, thanks.
@query = 'select ''First Name: '' + au_fname + char(13) + ''LastName: '' +
au_lname + char(13) from pubs.dbo.authors',
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joe | last post by:
I want to use mail() to send a message to a group of addresses in a mysql table. Išve got my mail script and my sql query, but I donšt know how to format the query results to fit into the mail()...
8
by: Adam Ruth | last post by:
Hello all, I've got what appears to be a bug in Oracle, but I don't want to make that judgement until I get someone's opinion who knows Oracle better than I. I'm running Oracle 8i on Solaris...
1
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100,...
0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
1
by: ljungers | last post by:
Hi and I hope that someone may have an answer for this, or an example of what I need to do. I have a Access database that a clerk will be entering a Order Number or Client Name or a Client City in a...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
1
by: igor221189 | last post by:
Hello everyone. I have Access 2000 database which holds student records in the school.It stores subject grades for each student.In the 'Student Grade Form', I would like to search student surname...
1
by: mcfly1204 | last post by:
I am generating an XML document using C#, and I have a question on how to populate the value of a particular object with the corresponding value from a SQL query. For example, if I have a query...
1
by: Dave Mallett | last post by:
very new to Access. Trying to export query results via macro and transfertext, but keep getting error message stating "Microsoft Jet Engine cannot find the object 'HRQ-DM_Prd1_qtr.txt'. Make sure...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.