Solved

need to format tablix cell based on data

Posted on 2011-02-15
5
1,294 Views
Last Modified: 2012-05-11
SSRS Newbie here.
Using SQL 2008 R2

I need to examine a report tablix cell and, if it begins with a certain text, say "xyz:" I need to change the background color of that cell and peel off the letters "xyz:".

So if the data was "xyz:Michigan" the report would show the word "Michigan" with a green background.

I know I can go into the textbox proprties fill property and do something like:
=Iif(ReportItems!State like "xyz:", "Green", "No Color")

So, for color changing the cell background, the problem is of course that SSRS doesn't like the "like" operator. What can I use in its place?

I'm not even sure where to begin on removing the "xyz:". Any ideas from our SSRS experts?

As a follow-up, does anyone have a good link to SSRS Expression examples? I've tried the one in MSDN (http://msdn.microsoft.com/en-us/library/ms157328.aspx) and while it has some good examples, none that really help me here.

Thanks in advance.
0
Comment
Question by:kalittaair
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 34903055
Ok here you go...
Place this code in your Report Properties Code Tab.......
Public Function ReplaceData(ByVal str As String, ByVal sData As String) As String
        Return System.Text.RegularExpressions.Regex.Replace(sData, str, "")
End Function

The str is the string you are searching for; and the sData is the whole data field that you are wanting to check.

Place this example code in your Textbox or Cell
=Code.ReplaceData("xyz", "xyz:Michigan")
on the report field more like this
=Code.ReplaceData("xyz",Fields!MyData.Value)
0
 

Author Comment

by:kalittaair
ID: 34916413
Planocz,

Firstly, thank you for your quick posting and I apologize for the delayed response. I've been out of the office.

This works great except when the data returned is NULL. In that case I get an "#Error" in my field. Sometimes the data coming back from the DB will be NULL. In that case it should do nothing, and just display no value. How can I handle that?

Also, any idea on how I can change the background color when the "xyz:" exists?

Thanks again.
0
 
LVL 27

Expert Comment

by:planocz
ID: 34919015
Change to this code

Public Function ReplaceData(ByVal str As String, ByVal sData As String) As String
        If IsNothing(str) then
           Return Nothing
        Else
           Return System.Text.RegularExpressions.Regex.Replace(sData, str, "")
       End If
       Return Nothing
End Function
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 34919093
0
 

Author Closing Comment

by:kalittaair
ID: 34921512
All works great. Thanks for all your help!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by Valentino Vranken. Introduction: In a previous article (http://www.experts-exchange.com/articles/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Reporting-On-Data-From-Stored-Procedures-part-1.html) I announced that I would writ…
Time Corrections for Reports Working with a report, we made some interesting discoveries about the time corrections/updates We are using the following Parameters: Starting Entered Date (Date) formatted as Data type: "Date/Time" Ending Entered …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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