Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need to format tablix cell based on data

Posted on 2011-02-15
5
Medium Priority
?
1,301 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 2000 total points
ID: 34919093
0
 

Author Closing Comment

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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

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 …
Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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