1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Query Builder】Sorting the result of UNION query

Posted at

Introduction

UNION query can be designed with Sharperlight Query Builder. It is useful for Combining data from different sources.

The final dataset is created as a stack of the results from each union query. While the results of each query can be sorted by specifying criteria, the entire final dataset cannot be sorted as a whole.

In this post, Let's see how to sort the final result of a UNION query in Sharperlight.

UNION Query

Creating a UNION query.
Open Query Builder from Sharperlight application menu.

The 1st Query (Parent Query)

Instead of actually retrieving the data from the database, I create a UNION query with the comma-separated datasets.
image.png
Choose System as Product.
Use Custom Define Dataset as Table.
Then create a dataset for the main query by clicking the lookup button.
This opens a text editor. Write the test data on it.
image.png

"Invoice Number::String","Amount::Number", "Data from::String"
"A100",1234.55,"Main Query"
"A200",1618.00,"Main Query"
"B300",3141.00,"Main Query"

Design the outputs like this.
image.png

The 2nd Query

Right-click on Outputs pan, and select Query Unions to define the 2nd query.
image.png
This opens the Query Unions manager. Click the New icon.
image.png
It creates the 2nd query entry.
image.png
Double-click on it or click Edit Query button.
This opens Query Builder, and the basic definition is inherited from the parent.
Just the custom dataset needs to be editted.
It's like this.

"Invoice Number::String","Amount::Number","Source::String"
"B200",1234.55,"The 2nd Query"
"B100",1618.00,"The 2nd Query"
"C100",3141.00,"The 2nd Query"

OK to save it, and Unions button is shown on the parent query builder.
image.png

Preview the query and the result dataset is like this.
image.png

Sorting

Let's configure for sorting the final result on Invoice Number.
Right-click on Outputs pan with the parent query, and select Cascade Query to define the 2nd query.
image.png
This opens Query Builder for the cascade query.
It's data source is the final result of the UNION query.
Select those three columns to Outputs.
Add Sort option to Invoice Number column.
image.png
Preview it and the dataset returned is sorted.
image.png
Click OK to save the cascade query.
Cascade Query button is shown on the parent query builder.
image.png

Now we can use this parent query with Sharperlight Publisher as a Web Report or with Sharperlight Excel Addin to extract the data onto a worksheet.
image.png

image.png

Afterword

This is a good option because it makes sorting UNION queries easier than before.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?