Solved

Setting Current Date in Stored Procedure HTML Report Emails Direct from SQL-Server

Posted on 2013-01-25
3
198 Views
Last Modified: 2013-10-07
I'm trying to show the current month in the following portion of code N'<caption>Monthy Revenue</caption> , I am not sure how to go about doing this as I am not familiar with HTML coding. I know how to obtain the current month through SQL
select datename(mm,getdate()) but how do I put that into the caption.

Below is the stored procedure

/****
Attribute:
http://www.wikihow.com/Send-a-Scheduled-HTML-Report-Directly-from-SQL-Server
SQL for Current Month select datename(mm,getdate())
****/


USE <database>
go

/****
DROP proc dbo.GetCurrentMonthyRevenue
GO
****/

create procedure dbo.GetCurrentMonthyRevenue
as
begin declare @query nvarchar(max)

set @query =
      N'<h1>Current Month Revenue</h1>' +
      N'<style type=''text/css''>'+
      N'table { border-collapse:collapse; border:1px solid #3399FF; font:10pt verdana; color:#343434; }'+
      N'table td, table th, table caption { border:1px solid #3399FF; }' +
      N'table caption { font-weight:bold; background-color:white; }'+
      N'</style>'+
      
      N'<table>' +
      N'<caption>Monthy Revenue</caption>' +
      N'<tr><th> Location </th><th> Revenue (Shipped) </th><th> Backlog (To Ship) </th><th> Total Est. Revenue
 </th></tr>' +
cast (
      (SELECT
                  td = LOCATION,'',
                  td = [REVENUE (Shipped)],'',
                  td = [BACKLOG (To Ship)],'',
                  td = [TOTAL EST. REVENUE],''
      FROM <database>.dbo.VE_BBB_Order_Summary_MTD_BYTotal
            ORDER BY [ORDER]
            for xml path ('tr'), type) as nvarchar(max)) +
            N'</table>'
select @query
end
go
0
Comment
Question by:TPBasintek
3 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38821437
Are you saying you want the current date here, "  N'<caption>Monthy Revenue</caption>' +"

as in   N'<caption>Monthy Revenue January</caption>' +


HTML does not produce the current date.  You would have to either place the date in via your sql meaning once saved, it will be static or use serverside code or javascript.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39552311
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 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

8 Experts available now in Live!

Get 1:1 Help Now