Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

dynamic query

$
0
0

Hi,

I want my report to show the request date field and value when the company !=50, but the syntax below keep getting an error, can anyone please help?

Thanks

DECLARE @tableHTML  NVARCHAR(MAX) ;

SET @tableHTML =
   N'<head>' +
    N'<style type="text/css">h2, body {font-family: Arial, verdana;} table{font-size:11px; border-collapse:collapse;} td{background-color:#F1F1F1; border:1px solid black; padding:3px;} th{background-color:#99CCFF;}</style>' +
   N'<h2><font color="#0000ff" size="4">Work Order </font></h2>' +   
   N'</head>' +
N'<body>' +
N' <hr> ' +
N' ' +


    N'<table border="1">' +
    N'<tr><th>Work Order ID</th><th>Product ID</th>' +
   case when @companyID !=50  then N'<th>Request Date</th>'  end +
    N'<th>Expected Revenue</th>

    </tr>' +
    CAST ( ( SELECT td = wo.WorkOrderID,  '',
                    td = p.ProductID, '',
case when @companyID !=50  then td = wo.DueDate  end ,'',               
                    td = p.ListPrice 
              FROM WorkOrder as wo
              JOIN Product AS p
              ON wo.ProductID = p.ProductID
              WHERE DueDate > '2006-04-30'
                AND DATEDIFF(dd, '2006-04-30', DueDate) < 2 

              FOR XML PATH('tr'), TYPE 
    ) AS NVARCHAR(MAX) ) +
    N'</table>' ;

EXEC msdb.dbo.sp_send_dbmail @recipients='test@cdd.com',
    @profile_name = 'mypr',
    @subject = 'work order',
    @body = @tableHTML,
    @body_format = 'HTML' ;

                          

Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>