SSRS 表达式中的粗体特定值

Bold Specific Values in Expression in SSRS

当值包含 "x" 时,我试图在表达式中创建多个值 "Bold"。 Html 占位符属性不符合我的需要,我正在努力让它与下面的内容一起使用,因为我的表达式中有多个语句:

=(IIF(字段!Test1.Value="x", "Bold", "Normal") 或 (字段!Test2.Value= "x"、"Bold"、"Normal") 等等等等

我想我需要创建一个自定义代码函数,然后在表达式中需要的地方调用该函数,但我不知道从哪里开始!任何帮助将不胜感激。

更新:

Switch 正在工作,但加粗了整个表达式,而不仅仅是在表达式的占位符属性中指定的值。我相信这是因为我的主要表达式连接了创建一个长字符串的字段。

Placeholder exp

Result

Value exp

+-----------+------------+-----------+------------------+------------------+-----------+-----------+------------+-----------+-------------------+---------+--------------+-----------+----------------+-------------------------------+-----------------+---------------+--------------+----------+------------------+------------------+------------------+------------------+------------+---+------------+-----------+-------------------+-----------+--------------+-----------+----------------+---------+----------+-------------------+----------------------+---------------+----------------+---------+
| id_number | first_name | last_name | pref_address_ind | h_addr_type_code | h_care_of | h_street1 | h_street2  | h_street3 | h_foreign_cityzip | h_city  | h_state_code | h_zipcode | h_country_code |        h_email_address        | p_email_address |    h_phone    |              | hc_phone | b_company_name_1 | b_company_name_2 | b_business_title | fld_of_work_code | b_street1  |   | b_street2  | b_street3 | b_foreign_cityzip |  b_city   | b_state_code | b_zipcode | b_country_code | b_phone | bc_phone |  b_email_address  |                      | full_business | pref_email_ind | Main_ID |
+-----------+------------+-----------+------------------+------------------+-----------+-----------+------------+-----------+-------------------+---------+--------------+-----------+----------------+-------------------------------+-----------------+---------------+--------------+----------+------------------+------------------+------------------+------------------+------------+---+------------+-----------+-------------------+-----------+--------------+-----------+----------------+---------+----------+-------------------+----------------------+---------------+----------------+---------+
|    165815 | Test       | Test1     | NULL             |                  | NULL      | NULL      | x Apt #09  | NULL      | NULL              | NULL    | NULL         | NULL      | x USA          | NULL                          | NULL            | DELETED       |              | DELETED  | NULL             | ~                | NULL             | NULL             | NULL       |   | NULL       | NULL      | NULL              | NULL      | NULL         | NULL      | NULL           | NULL    | NULL     | NULL              |                      | NULL          | NULL           |  165815 |
|    165816 | Test       | Test2     | NULL             |                  | NULL      | Street    | x Street 1 | x Street2 | NULL              | Houston | NULL         | NULL      | NULL           | x Home Email:testing@test.com | NULL            | x Home Phone: | 111-111-1111 | NULL     | NULL             | ~                | NULL             | NULL             | x Business | 1 | x Street 2 | NULL      | NULL              | x Houston | x TX         | x 77777   | NULL           | NULL    | NULL     | x Business Email: | btesting@testing.com | NULL          | NULL           |  165816 |
+-----------+------------+-----------+------------------+------------------+-----------+-----------+------------+-----------+-------------------+---------+--------------+-----------+----------------+-------------------------------+-----------------+---------------+--------------+----------+------------------+------------------+------------------+------------------+------------+---+------------+-----------+-------------------+-----------+--------------+-----------+----------------+---------+----------+-------------------+----------------------+---------------+----------------+---------+

应该不需要自定义代码,尽管这取决于您可能要考虑的规则的复杂程度SWITCH

根据您的简单示例,您可以执行以下任一操作

=IIF(
     Fields!Test1.Value = "x" OR Fields!Test2.Value = "x",
     "Bold", 
     Nothing)

或更复杂的情况

= SWITCH (
          Fields!Test1l.Value = "x" OR Fields!Test2.Value="x", "Bold",
          Feilds!Test3.Value = "Z" AND Fields!Test4.Value >10, "SemiBold",
          True, Nothing)

SWITCH 评估每个 expression/result 对,并在遇到第一个评估为 True 时停止。最后的 'True, Nothing' 就像一个 else。 SWITCH if 比嵌套 IIF 更容易阅读,但如果规则简单,IIF 可以更简单。

更新:

以下显示使用数据集查询中生成的 HTML 执行此操作。我对 HTML 几乎一无所知,这可能是可以解决的,但这是我要去的地方....

根据您的示例 table,我使用 </p> 创建了一个包含地址 HTML 版本的新列来创建换行符。

它还会抑制空行。

sql 看起来像

SELECT 
    HomeAddrFormattedP1 = '<p>Home Address: </p>' 
                        + IIF( ISNULL(h_street1,'')='', '', IIF( LEFT(h_street1,1) = 'x', '<b>' + h_street1 + '</b></p>', h_street1 + '</p>') )
                        + IIF( ISNULL(h_street2,'')='', '', IIF( LEFT(h_street2,1) = 'x', '<b>' + h_street2 + '</b></p>', h_street2 + '</p>') )
                        + IIF( ISNULL(h_street3,'')='', '', IIF( LEFT(h_street3,1) = 'x', '<b>' + h_street3 + '</b></p>', h_street3 + '</p>') )
                        + IIF( ISNULL(h_foreign_cityzip,'')='', '', IIF( LEFT(h_foreign_cityzip,1) = 'x', '<b>' + h_foreign_cityzip + '</b></p>', h_foreign_cityzip + '</p>') )
                        + IIF( ISNULL(h_city,'')='', '', IIF( LEFT(h_city,1) = 'x', '<b>' + h_city + '</b></p>', h_city + '</p>') )
                        + IIF( ISNULL(h_state_code,'')='', '', IIF( LEFT(h_state_code,1) = 'x', '<b>' + h_state_code + '</b></p>', h_state_code + '</p>') )
                        + IIF( ISNULL(h_zipcode,'')='', '', IIF( LEFT(h_zipcode,1) = 'x', '<b>' + h_zipcode + '</b></p>', h_zipcode + '</p>') )
                        + IIF( ISNULL(h_country_code,'')='', '', IIF( LEFT(h_country_code,1) = 'x', '<b>' + h_country_code + '</b></p>', h_country_code + '</p>') )                        
    , 
    *
FROM myTable

将其用作我的报告的数据集查询,然后我添加了一个简单的 table,其中包含 3 列,其中一列用于 HomeAddrFormattedP1first_namelast_name

然后我所做的就是右键单击 HomeAddrFormattedP1 占位符并将其属性设置为标记类型 = HTML

最终结果如下。