Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Apply Style in Select Query


Apply Style in Select Query

Author
Message
parth83.rawal
parth83.rawal
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 160
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


Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16576 Visits: 17020
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14958 Visits: 38972
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 [TD],
product As [TD],
provider As [TD],
data_source As [TD style="width: 210px;min-width: 100px"],
is_linked As [TD align="center"]
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

parth83.rawal
parth83.rawal
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 160
Worked for me thanks!
mister.magoo
mister.magoo
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2270 Visits: 7827
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 [TD],
'' AS [*], -- Blank, just here to prevent element merging
product As [TD],
'' AS [*],
provider As [TD],
'' AS [*],
'width: 210px;min-width: 100px' AS [TD/@style],
data_source As [TD],
'' AS [*],
'center' AS [TD/@align],
is_linked As [TD]
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);




  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Go


    Permissions

    You can't post new topics.
    You can't post topic replies.
    You can't post new polls.
    You can't post replies to polls.
    You can't edit your own topics.
    You can't delete your own topics.
    You can't edit other topics.
    You can't delete other topics.
    You can't edit your own posts.
    You can't edit other posts.
    You can't delete your own posts.
    You can't delete other posts.
    You can't post events.
    You can't edit your own events.
    You can't edit other events.
    You can't delete your own events.
    You can't delete other events.
    You can't send private messages.
    You can't send emails.
    You can read topics.
    You can't vote in polls.
    You can't upload attachments.
    You can download attachments.
    You can't post HTML code.
    You can't edit HTML code.
    You can't post IFCode.
    You can't post JavaScript.
    You can post emoticons.
    You can't post or upload images.

    Select a forum

































































































































































    SQLServerCentral


    Search