Solved

need to format tablix cell based on data

Posted on 2011-02-15
5
1,292 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Closing Comment

by:kalittaair
Comment Utility
All works great. Thanks for all your help!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Introduction: This article is aimed at report developers who are used to developing reports using relational databases and have gotten a first-time assignment to develop reports on OLAP cubes. It demonstrates how to build a report using SQL Ser…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now