locked
changing the font color of a row using select statement RRS feed

  • Question

  • Hi All,

    I am using SQL Server2008 R2. I need to get the red color in grid when i applied select statement. I have tried with below query.

    But not getting the result. In query result i am getting the result as 

     <font color=red>Park Innah Holiday 07:00-17:00</font>

    INSERT INTO #tmpscheduling SELECT  DISTINCT '' AS SchShiftId,'Unavailability' AS shiftdesc,'' AS shortskillname
        ,'' AS sortorder,'' AS skillorder,CAST(2 as int) as id, STUFF((
        SELECT ', '+ CAST(Col1 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN1,STUFF((
        SELECT ', '+ CAST(Col2 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN2
        ,STUFF((
        SELECT ', '+ CAST(Col3 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN3,STUFF((
        SELECT ', '+ CAST(Col4 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN4,STUFF((
        SELECT ', '+ CAST(Col5 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN5,STUFF((
        SELECT ', '+ CAST(Col6 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN6,STUFF((
        SELECT ', '+ CAST(Col7 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN7,STUFF((
        SELECT ', '+ CAST(Col8 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN8,STUFF((
        SELECT ', '+ CAST(Col9 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN9,STUFF((
        SELECT ', '+ CAST(Col10 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN10,STUFF((
        SELECT ', '+ '<font color=red>' + CAST(Col11 as VARCHAR(5000)) + '</font>'
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN11,STUFF((
        SELECT ', '+ '<span style=color: rgb(255, 0, 0)>'+  CAST(Col12 as VARCHAR(5000)) +'</span>'
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN12,STUFF((
        SELECT ', '+ CAST(Col13 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN13,STUFF((
        SELECT ', '+ CAST(Col14 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN14,STUFF((
        SELECT ', '+ CAST(Col15 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN15,STUFF((
        SELECT ', '+ CAST(Col16 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN16,STUFF((
        SELECT ', '+ CAST(Col17 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN17,STUFF((
        SELECT ', '+ CAST(Col18 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN18,STUFF((
        SELECT ', '+ CAST(Col19 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN19,STUFF((
        SELECT ','+ CAST(Col20 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN20,STUFF((
        SELECT ', '+ CAST(Col21 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN21,STUFF((
        SELECT ', '+ CAST(Col22 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN22,STUFF((
        SELECT ', '+ CAST(Col23 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN23,STUFF((
        SELECT ', '+ CAST(Col24 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN24,STUFF((
        SELECT ', '+ CAST(Col25 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN25,STUFF((
        SELECT ', '+ CAST(Col26 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN26,STUFF((
        SELECT ', '+ CAST(Col27 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN27
        ,STUFF((
        SELECT ', '+ CAST(Col28 as VARCHAR(5000)) 
        FROM #tmptable
        WHERE shiftdesc LIKE '%Unavailability%'
        FOR XML PATH('')
        )
        ,1,1,'') AS COLUMN28
        FROM #tmptable

    Please guide me how i can achieve this

    Monday, August 21, 2017 1:30 PM

Answers

  • i am using telerikrad grid. I can't go with reporting tools.

    And we are expected to know what that is? It may just go to show how un-hip I am, but I have never heard of it.

    If you know how to code for colouring in that grid thing explain and we can help you with the SQL part.

    If you don't know how to colour things in telerikrad in general, you are in the wrong forum. You need a forum for telerikrad.

    • Marked as answer by Sai Pranav Wednesday, August 23, 2017 7:14 AM
    Monday, August 21, 2017 1:51 PM
  • All SQL returns is data.  Telerikrad is going to interpret that text.  It might just display it as black text (or blue).

    So, back to Erland's point.  You need someone who knows Telerikrad to instruct you as to what data SQL will need to provide to display in different colors.


    Russel Loski, MCSE Data Platform/Business Intelligence Twitter: @sqlmovers; blog: www.sqlmovers.com

    • Marked as answer by Sai Pranav Wednesday, August 23, 2017 7:14 AM
    Monday, August 21, 2017 2:15 PM
  • Hi All,

    I am using SQL Server2008 R2. I need to get the red color in grid when i applied select statement. I have tried with below query.

    But not getting the result. In query result i am getting the result as 

     &lt;font color=red&gt;Park Innah Holiday 07:00-17:00&lt;/font&gt;

    .....


    Please guide me how i can achieve this

    Hi Sai,

    Like everyone said, you are not at the right Forum. Your question is a Telerik question, related to customizing appearance of a RadGrid cell, and you can get better answers at the Telerik forums.

    That being said, looking at Telerik RadGrid online documentation there are instructions about how to achieve what you want. Please look at this Telerik link:

    Conditional Formatting

    Let me know if you still have issues.



    My Technet Articles

    If you like this or another reply, vote it up!
    If you think this or another reply answers the original question, mark it or propose it as an answer.


    Mauricio Feijo
    www.mauriciofeijo.com


    • Edited by Mauricio Feijo Monday, August 21, 2017 3:26 PM
    • Proposed as answer by Russ Loski Monday, August 21, 2017 5:16 PM
    • Marked as answer by Sai Pranav Wednesday, August 23, 2017 7:13 AM
    Monday, August 21, 2017 3:25 PM

All replies

  • First of all, what grid are you talking about?  SQL Server Management Studio does almost no formatting of data.  The only formatting I recall is that cell of a NULL is colored differently.

    If you need to color things conditionally, I would use reporting services.


    Russel Loski, MCSE Data Platform/Business Intelligence Twitter: @sqlmovers; blog: www.sqlmovers.com

    Monday, August 21, 2017 1:37 PM
  • i am using telerikrad grid. I can't go with reporting tools.
    Monday, August 21, 2017 1:40 PM
  • i am using telerikrad grid. I can't go with reporting tools.

    And we are expected to know what that is? It may just go to show how un-hip I am, but I have never heard of it.

    If you know how to code for colouring in that grid thing explain and we can help you with the SQL part.

    If you don't know how to colour things in telerikrad in general, you are in the wrong forum. You need a forum for telerikrad.

    • Marked as answer by Sai Pranav Wednesday, August 23, 2017 7:14 AM
    Monday, August 21, 2017 1:51 PM
  • According to the sp i have no option to change the color through front-end. Because of that i expected the color may applicable with select statement. Please correct me if i  am wrong.
    Monday, August 21, 2017 2:02 PM
  • All SQL returns is data.  Telerikrad is going to interpret that text.  It might just display it as black text (or blue).

    So, back to Erland's point.  You need someone who knows Telerikrad to instruct you as to what data SQL will need to provide to display in different colors.


    Russel Loski, MCSE Data Platform/Business Intelligence Twitter: @sqlmovers; blog: www.sqlmovers.com

    • Marked as answer by Sai Pranav Wednesday, August 23, 2017 7:14 AM
    Monday, August 21, 2017 2:15 PM
  • Hi All,

    I am using SQL Server2008 R2. I need to get the red color in grid when i applied select statement. I have tried with below query.

    But not getting the result. In query result i am getting the result as 

     &lt;font color=red&gt;Park Innah Holiday 07:00-17:00&lt;/font&gt;

    .....


    Please guide me how i can achieve this

    Hi Sai,

    Like everyone said, you are not at the right Forum. Your question is a Telerik question, related to customizing appearance of a RadGrid cell, and you can get better answers at the Telerik forums.

    That being said, looking at Telerik RadGrid online documentation there are instructions about how to achieve what you want. Please look at this Telerik link:

    Conditional Formatting

    Let me know if you still have issues.



    My Technet Articles

    If you like this or another reply, vote it up!
    If you think this or another reply answers the original question, mark it or propose it as an answer.


    Mauricio Feijo
    www.mauriciofeijo.com


    • Edited by Mauricio Feijo Monday, August 21, 2017 3:26 PM
    • Proposed as answer by Russ Loski Monday, August 21, 2017 5:16 PM
    • Marked as answer by Sai Pranav Wednesday, August 23, 2017 7:13 AM
    Monday, August 21, 2017 3:25 PM