February 4, 2010 at 4:31 am
Hi,
I have a simple select output that i need to send to a user through email from sql server 2005.
Hence i need to convert my sql select output into htmltable. how would i ?
[Code]
select Name,EmailAddress,ExpiryDate from tblSubscribers
[/Code]
Expected Output
-----------------
<table><tr><td></td></tr></table> and so on...
Thanks.
February 4, 2010 at 4:44 am
I'm not really into HTML so there may be something wrong with the formatting, but this should be enough to get you there (I developed the sample on the AdventureWorks2008 database).
DECLARE @out VARCHAR(MAX) = '<table>' ;
SELECT @out = @out + '<tr><td>' + [AddressLine1] + '</td><td>' + [City] + '</td><td>' + [PostalCode] + '</td></tr>'
FROM [Person].[Address]
WHERE [AddressID] < 10
SELECT @out + '</table>'
Be careful if any of your data fields can be NULL -> it will make the entire result NULL. In that case you should wrap the column as follows:
ISNULL([AddressLine1],'')
You can also replace '' with a string like e.g. ISNULL([AddressLine1],'empty')
February 4, 2010 at 3:45 pm
I'm not sure that it will do exactly what you want and I believe it's been deprecated in 2k5, but take a look at sp_MakeWebTask in Books Online.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 4, 2010 at 11:39 pm
Thank you wschampheleer. Some minor changes done and it worked.
February 5, 2010 at 5:21 am
Jeff Moden (2/4/2010)
I'm not sure that it will do exactly what you want and I believe it's been deprecated in 2k5, but take a look at sp_MakeWebTask in Books Online.
I am not sure which feature you talking about that is deprecated, but for sp_MakeWebTask BOL says
sp_makewebtask is retained for backward compatibility. New Web pages are more easily created using Microsoft SQL Server 2005 Reporting Services (SSRS).
To execute sp_makewebtask you must be a member of the sysadmin fixed server role.
This feature will be removed in the next version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible.
--Ramesh
February 5, 2010 at 5:28 am
Be careful if any of your data fields can be NULL -> it will make the entire result NULL. In that case you should wrap the column as follows:
ISNULL([AddressLine1],'')
You can also replace '' with a string like e.g. ISNULL([AddressLine1],'empty')
Rather than use ISNULL you could use this at the top of your script.
SET CONCAT_NULL_YIELDS_NULL OFF ;
It's easier than using ISNULL many times if you have lots of fields.
February 5, 2010 at 9:20 am
Ramesh Saive (2/5/2010)
Jeff Moden (2/4/2010)
I'm not sure that it will do exactly what you want and I believe it's been deprecated in 2k5, but take a look at sp_MakeWebTask in Books Online.I am not sure which feature you talking about that is deprecated, but for sp_MakeWebTask BOL says
sp_makewebtask is retained for backward compatibility. New Web pages are more easily created using Microsoft SQL Server 2005 Reporting Services (SSRS).
To execute sp_makewebtask you must be a member of the sysadmin fixed server role.
[font="Arial Black"]This feature will be removed in the next version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible. [/font]
The same one you quoted... "deprecated" means "still available but going away soon". 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
February 6, 2010 at 12:53 am
Jeff,
Nobody has mentioned about the deprecated procedure expect you, so I was little confused, but now everything is fine.
--Ramesh
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply