October 4, 2012 at 10:48 pm
Hi,
I am using FOR XML to generate the HTML and following is my query. i want to apply class in td, how can i achieve the same ??
CAST ( ( SELECT td=Row_Number() over( Order by TaskIndex),'',
td = [ProjectServer_NPD_Reporting].dbo.Fn_Task_Wbs(P.Projectuid,convert(char,TaskWBS)), '' ,
td=[TaskName],'',
td = CONVERT(VARCHAR,[TaskStartDate],6), '' ,
td = CONVERT(VARCHAR,[TaskFinishDate],6), '',
td = CONVERT(VARCHAR,[TaskPercentCompleted])+'% Complete', ''
from
October 5, 2012 at 7:43 am
parth83.rawal (10/4/2012)
Hi,I am using FOR XML to generate the HTML and following is my query. i want to apply class in td, how can i achieve the same ??
CAST ( ( SELECT td=Row_Number() over( Order by TaskIndex),'',
td = [ProjectServer_NPD_Reporting].dbo.Fn_Task_Wbs(P.Projectuid,convert(char,TaskWBS)), '' ,
td=[TaskName],'',
td = CONVERT(VARCHAR,[TaskStartDate],6), '' ,
td = CONVERT(VARCHAR,[TaskFinishDate],6), '',
td = CONVERT(VARCHAR,[TaskPercentCompleted])+'% Complete', ''
from
Can you post the whole query?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 5, 2012 at 9:45 am
does this example, where I'm applying some styles to the results help?
note i have to do a find/replace to the string to unescape some characters;
DECLARE @HTMLBody varchar(max)
Select @HTMLBody = (Select Row_Number() Over(Order By is_linked, name) % 2 As [TRRow],
name As
,
product As
,
provider As
,
data_source As
,
is_linked As
From sys.servers
Order By is_linked, name
For XML raw('tr'), Elements)
Set @HTMLBody = Replace(@HTMLBody, '_x0020_', space(1))
Set @HTMLBody= Replace(@HTMLBody,'_x0022_','"')
Set @HTMLBody= Replace(@HTMLBody,'_x003B_',';')
Set @HTMLBody = Replace(@HTMLBody, '_x003D_', '=')
Set @HTMLBody = Replace(@HTMLBody, '<tr><TRRow>1</TRRow>', '<tr bgcolor="#C6CFFF">')
Set @HTMLBody = Replace(@HTMLBody, '<TRRow>0</TRRow>', '')
Select '<table>' + @HTMLBody + '</table>'
Lowell
October 6, 2012 at 12:21 am
Worked for me thanks!
October 6, 2012 at 8:48 am
parth83.rawal (10/6/2012)
Worked for me thanks!
Please also consider this - it is a lot faster and neater IMHO...
SELECT '#C6CFFF' AS [@bgcolor],
s.name As
,
'' AS [*], -- Blank, just here to prevent element merging
product As
,
'' AS [*],
provider As
,
'' AS [*],
'width: 210px;min-width: 100px' AS
,
data_source As
,
'' AS [*],
'center' AS
,
is_linked As
FROM sys.servers s,syscolumns
ORDER BY is_linked, s.name
FOR XML PATH('TR'),ROOT('TABLE')
I know this looks odd, but that is just because we are using XML to craft HTML. The main difference for this query being that HTML commonly has repeated elements (The TD elements), where XML doesn't tend to.
What this means for this query is that we need to find a way round the in-built functionality in FOR XML PATH that merges consecutive elements that have the same TAG. The way to stop this is either to alternate between upper and lower case TDs, OR as in this example, to use a blank to break the rule.
Generally, here we have a ROOT('TABLE') for the whole query, a row tag - FOR XML PATH('TR') and we have attributes, which come at the start of the SELECT for row attributes, but come before each individual TAG.
I think, in general you will find this method to be faster, neater and easier to produce the correct output.
For comparison, here is the output from Lowell's method
<table>
<tr bgcolor="#C6CFFF">
<TD>COMP1</TD>
<TD>SQL Server</TD>
<TD>SQLNCLI</TD>
<TD style="width: 210px;min-width: 100px">COMP1</TD style="width: 210px;min-width: 100px">
<TD align="center">0</TD align="center">
</tr>
</table>
And the output from this method
<TABLE>
<TR bgcolor="#C6CFFF">
<TD>COMP1</TD>
<TD>SQL Server</TD>
<TD>SQLNCLI</TD>
<TD style="width: 210px;min-width: 100px">COMP1</TD>
<TD align="center">0</TD>
</TR>
</TABLE>
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply