SSRS - Display grouped detail columns in multiple rows in section - reporting-services

I have to prepare a report in SSRS and getting a result set of stocks group by on stock number. I have show some columns in one row but others beneath this row and 5 separated rows. Its a detail report should be displayed in section like below. All columns in dataset are in one row. I have tried many ways but cannot create such format. Please SSRS experts provide some suggestions.
Stock# Description Inventory column4 column5 column6 column7
00001 Some stock 9034 122 xyz 123 ABC
--------------------------------------------------------------------------------
Product: Product1
Catalog: Catalog1
Buyer : Buyer Vendor-1: Vendor1 Price:455 Date:mm/dd/yy
Alias : xyz
Notes: comments
Tendor#: 4334 Vendor:Vendorx
--------------------------------------------------------------------------------
Totals: 89908.7998
00002 Some stock 8034 422 xyz 123 ABC
--------------------------------------------------------------------------------
Product: Product2
Catalog: Catalog2
Buyer : Buyer2 Vendor-2: Vendor2 Price:555 Date:mm/dd/yy
Alias : xyz
Notes: comments2
Tendor#: 5634 Vendor:Vendorx
--------------------------------------------------------------------------------
Totals: 89908.7998

I got the solution. Use List control and found this at this link.
http://blogs.technet.com/b/microsoft_in_education/archive/2013/03/09/ssrs-using-a-list-item-to-display-details.aspx
Got what I was looking.

Related

Query to extract data based on one column value

There are 2 tables that are supposed to have unique product codes but I came across a case where the product code ended up the same for two of the records in another table. I would like to get the product information based on the latest product year. Let's assume I have the following tables.
Table 1:
recall
id
product_year
product_code
yes
200
2019
3222333
no
201
2020
3222333
yes
202
2021
4332233
no
203
2021
5446553
yes
204
2018
6556677
Table 2:
recall
id
product_year
product_code
no
100
2019
2245643
yes
101
2020
1234543
no
102
2017
4332233
yes
103
2022
5446553
yes
104
2018
3344566
Table 3 contains only unique product code information and other updated information based on the latest product year. For eg: product code 3222333 has only one entry even though Table 1 has 2 entries for 3222333. But the problem comes for codes 4332233 and 5446553 which are present in both Table 1 and Table 2.
Table 3:
country
id
product_code
Brazil
301
3222333
Indonesia
302
4332233
Argentina
303
6556677
Chile
304
2245643
Brazil
305
1234543
Chile
306
5446553
USA
307
3344566
It is known that Table 3 doesn't contain correct data. But I would like to generate a query in mysql to get all the product codes from Table 3 and get the product code related information based on the latest product year. Earlier I was using something like COALESCE(table1.recall, table2.recall, null) assuming that only one value will be present and it works. But for the codes 4332233 and 5446553, it will always pick table 1 column value as recall values for the same product codes are present in both tables 1 and 2. How should I deal with this problem so that I get the data only based on the latest product year?
Expected output:
country
product_code
recall
Brazil
3222333
no
Indonesia
4332233
yes
Argentina
6556677
yes
Chile
2245643
no
Brazil
1234543
yes
Chile
5446553
yes
USA
3344566
yes
It did take me some time to realise how convenient it is to use UNION in this case. Below is the code written and tested in workbench.Please note this is currently the best answer I can come up with based on the limited table structure and sample data you provided. Since you say that it's possible for the same product_code to have the same product_year in both table1 and table2 and you have other means to determine the latest one, please tweak the code as you see fit. Hope this helps solve your issue.
select country, recall,ta.product_code as product_code
from
(select product_code,product_year,recall
from table1 t1
union
select product_code,product_year,recall
from table2 t2
) ta
join
(select product_code p_c,max(product_year) mx_y
from
(select product_code,product_year
from table1 t1
union
select product_code,product_year
from table2 t2
) t_union
group by product_code
) tb
on ta.product_code=p_c and ta.product_year=mx_y
join table3 t3
on p_c=t3.product_code
;

How to check if json array of values present in one table is present in another table using SQL?

I have two tables that look like this..
Baskets
id
Array
1
["Apple", "Mango", "Pineapple"]
2
["Mango", "Pineapple"]
3
["Dragonfruit"]
Stock
Fruit
Count
Apple
100
Mango
500
Kiwi
99
Grapes
0
Through a SQL query, I have to check how many fruits from an array of the first table are present in the second table.
For example, out of ["Apple", "Mango", "Pineapple"] only Apple and Mango is in the Stock table.
Expected outcome:
id
available
1
2
2
1
3
0
PS. this is a simplification of the actual problem I'm trying to solve, my main query is how to match a JSON array of objects against some other table. The fruits/stock example is just for explaining the problem.
SELECT Baskets.id, COUNT(Stock.Fruit) available
FROM Baskets
LEFT JOIN Stock ON JSON_SEARCH(Baskets.Array, 'one', Stock.Fruit) IS NOT NULL
GROUP BY Baskets.id
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=a0f8e8fba8851fcda508affca0201ba9

SQL difficult statement

Currently I'm looking for a solution. English is not my native language so I added two pictures to clarify it a bit. My knowledge of SQL is rather basic.
A chair (end-product) contains several components. Each component contains an item number, each spare set contains multiple item numbers. In the database a spare set is in the same table as an end-product. The chairs and spare parts are categorized in different groups.
Is it possible to create a table like that? If it's possible how?
Thanks in advance!
This would be my approach:
Table: Products -- a table of products
ProductID ProductName DateAdded
1 Chair X 01/01/2016
2 Chair Y 05/05/2016
3 Spare Set A 06/06/2016
...
Table: Components -- a table of components
ComponentID ComponentName ItemNumber DateAdded
1 Backrest X01 01/01/2016
2 Headrest X02 01/01/2016
...
Table: ProductComponent -- a lookup/mapping table to link Product and Component
PCID ComponentID ProductID DateAdded
1 1 1 01/01/2016
2 2 1 01/01/2016
...
DateAdded is the date the product or component was first entered into the database. It is for audit purposes.

SQL Matching Rows

I am in trouble matching a value in other table and get the corresponding value. I have two tables, table one for product and table 2 for part, I need to match part no from second table with oe number of first table and get SKU.
The problem is OE Number is a bunch of numbers and i need to use something like instr. For Example the table look like this.
Product Table
OeNum | SKU
123-546-625 | A001
568-623-855 | A002
Part Table
PArtid
623
625
for example I need to check if any row in OENUM have the string like part number and if there is one return the SKU. In above example partid 623 is in the second row of oenumber so it return value as
partID | SKU
623 | A002
625 | A001
i am using the query as :
select s.sku, p.id
from sk s, part p
where instr(s.oenum,p.id)>0;
but it doesn't seems to be working.
Please help.
If there are not very much data in your tables I can offer you to try something like:
select s.sku, p.id from sk s join part p on s.oenum like '%'+p.id+'%'

How do I group values by row in SSRS?

I am new to SSRS and need some help.
I am using a Matrix to Pivot my data.
Dataset looks like this:
TEST TOOLID
----- ------
TEST1 123
TEST1 234
TEST2 456
What I currently have is this:
TEST1 TEST2
TOOL ID 123 N/A
TOOL ID 234 N/A
TOOL ID N/A 456
The output I am looking for is (NULLS should be converted to N/A):
TEST1 TEST2
TOOL ID 1 123 456
TOOL ID 2 234 N/A
Thanks
jlimited
Choose Details in lower left of view pane under 'Row Groups'
Right Click>Add Group>Parent Group
Choose your item you want to group by, include header is the standard behavior(check box to select). Hit okay.
You are now grouping your columns and you should see a bit more geometric ( in the gray space before the rows showing they are grouped accordingly now.