Expressions in Report Builder (SSRS)- Paginated Report

本文展示了如何使用SQLServerReportingService的ReportingBuilder处理来自不同国家客户的定制报告需求,包括实时货币汇率转换、电子邮件地址验证以及多参数筛选功能。通过创建XML数据源、自定义函数和参数设置,实现灵活的报表生成和部署。
摘要由CSDN通过智能技术生成

we will demonstrate how to handle problems that may arise from the client or business.

Because when we create a report for clients, they can request very different features. Our scenario is that we have a client who sells the product to different countries, so we are developing a report for this client. We will find a solution for different needs of this client.

You can download Report Builder 2017 in this link and you can install it. At the startup, a screen comes up like below. In this screen, we will click blank report and create a new report.

We will create sample sales data and retrieve data to report.

CREATE TABLE SalesCurrency

(ID INT IDENTITY(1,1) PRIMARY KEY,

SalesAmount FLOAT ,

Cur VARCHAR(10),mail VARCHAR(50))

INSERT INTO SalesCurrency

VALUES (20,'USD' ,'testQQtest.com') ,(10,'GBP','sample.sample.cox'),

(60,'EUR','invalidemail@h.cooom'),

('15','JPY','invalid@lll.coz'),('92','EUR','ppl@test.com')

Client Request: Could you show my different currency sales in USD and exchange the real-time currency rates?

Response: Yes, we can handle this problem in three steps on Reporting Builder!

What to do?

  • We will create an XML datasource that retrieves the daily exchange rates
  • We will create a dataset and connect this dataset to XML data source
  • We will use lookup function and exchange all different currency sales to USD

First of all, we will add a datasource to our report.

Then we will select XML connection type and setup a connection string which returns exchange rates. This link will return USD exchange rates. You can find a lot of links which returns exchange rates in different currencies.

We will add a dataset, connect this dataset to XML datasource and click refresh fields.

Now our XML dataset is ready. We will add new datasource and dataset which retrieves sales data from SQL Server database.

We will write our query to query textbox.

We will add the table and then drag and drop “SalesAmount” and “Cur” fields to table.

When we run the report, it will look something like this.

The most important point in this demo is that we will use the Lookup function. The Lookup function helps us to return matching exchangeRate from XML datasource. It means that the Lookup function helps to find matching values from a different dataset.

The Lookup function gets the following parameters:

  • Lookup(source_expresion,destination_experission,result_experssion,dataset)
  • source_expresion : specify the value that we want to lookup. In our example, this value would be “Currency” column.
  • destination_experission : specify the value that we have to match from source dataset. In our example, this value would be “TargetCurrency”
  • result_experssion: specify the value which we want to return. In our example, this value would be “exchangeRate”
  • dataset : specify the destination dataset name.

Now, we will add a new column to the table and write the Lookup function and exchange currency to USD.

We will write Lookup experession for converting sales amounts to USD.

Fields!SalesAmount.Value*IIF(Fields!Cur.Value=”USD”,1,Lookup(Fields!Cur.Value,Fields!targetCurrency.Value,1/val(Fields!exchangeRate.Value), “XmlCurrencyDataSource”))

Finally, our report will show converted sales amount.

Client Request: Can you validate an email address using regex function?

Response: Yes, we can handle this problem by creating custom code using regex.

What to do?

  • We will write custom function code in report builder.
  • We will use a custom function in the report.

Now we will open report parameters and then click code tab. We will add custom function code which will validate e-mail addresses. In Report Builder we can use VB.net code.

Function validateEmail(emailAddress) As Boolean

        Dim email As New System.Text.RegularExpressions.Regex("([\w-+]+(?:\.[\w-+]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7})")

        If email.IsMatch(emailAddress) Then

            Return True

        Else

            Return False

        End If

    End Function

In this step, we will add two columns into the table which are “Mail” and “MailValidate” columns. We will write an expression for “Mailvalidate” column.

We will set expression for “MailValidate” column. This custom function will use our custom code and check mail validation.

And finally, we will run our report.

Client Request: Can you add filter sales currency with multiple parameters and show selected parameters?

Response: Yes, we can handle this problem to add multiple parameters.

How will we solve this?

  • We will add a report parameter
  • We will get report parameter values from XML data source
  • We will filter sales with this parameter

Now we will add report parameter and get parameter values from XML data source

We will select “Available Values” tab and chose “Get values from a query”. Then, we will select XML dataset and set the “Value Field” and “Label Field”.

The Value field defines a value which filters the dataset

The Label field defines a text which is shown in parameter description

We will set multiple “Allow multiple values”. This parameter lets us to select multiple values in the parameter. The “Prompt” text box defines a text which is shown in report parameter.

In this step, we will filter the sales dataset. We will open the dataset properties.

In “Filters” tabs we will add new filter expression and set report parameter to this expression. Here, we will use “In” operator because we want to select multiple parameters.

When we run the report, we are able to see report parameter. This parameter will filter the report.

If we want to show selected values, we have to use join function. And after that, we will add a text box to report and write a join expression.

How to open Reporting Service reports and deploy reports

If we want to deploy reports to Reporting Services, we will select “File tab” and select “Save As” and then select “Recent Sites and Servers”. We will include the Reporting Service URL.

And then select the folder and save the report.

Finally, our report is ready to use in Reporting service.

Conclusion

In this article, we focused on SQL Server Reporting Service Report Builder. This light-weight tool helps us to create reports and publish reports to Reporting Service. If companies are using Reporting Service in their reporting and business intelligence solutions, the Report Builder can provide for creating reporting or self-service BI (Self-Service BI approach helps business users to develop their own reports without the need of IT department. With this approach, business users get rid of dependence on IT department.).

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值