RDLC report: more than one page? Custom page breaks? - reporting-services

I have a Microsoft Reporting Services report (local report, VS2005) and am trying to produce a rather tricky report...
I have two tables returned from a SQL query. The first is a master table that has a list of set ID's corresponding to sets of records in the second, and has a record set like so:
+----------------------+
| SetID |
+----------------------+
| 1 |
| 2 |
| 3 |
| ... |
| |
The second table is a list of bjorks, let's call them. It looks like this:
+----------+-------+-----------+-----------
| BjorkID | SetID | BjorkName | ...
+----------+-------+-----------+-----------
| 1 | 1 | Bob |
| 2 | 1 | Jones |
| 3 | 1 | Smith |
| 4 | 2 | Jack |
| 5 | 2 | Daniels |
| 6 | 3 | Moo |
| 7 | 3 | Bean |
| 8 | 3 | Bond |
| 9 | 3 | Jim |
| ... | ... | ... |
| | | |
Now, I need to generate a report that prints off one page for each Set, and each Set's page contains a list of its Bjorks.
Can anyone point me in the right direction to mangle RDLC into doing this? :)
Cheers!

You can accomplish your task with just the second table/data set and parent and detail groups on a table or list.
Parent groups on SetID. Detail groups on BjorkID. Set your page breaks accordingly.
HTH

Related

MYSQL multi JOIN from different tables

I have multiple MYSQLI tables for multiple details and options about a touristic package.
I have package containing the main information, then I have package_option which contains unknown number of options added to the package, and there's package_images which contains the images.
I want to get all the information in one query, but it's prooving a difficult task. Let me explain.
I've used JOIN with but the problem was if the package_option had 3 options and the package_images had 6 images, the result was a 6*4 plus 1 (package) result table.
I would like a result containing all the fields, as many as they originaly are in the tables, not multiplied for each match in every table.
For example, the table I aim for looks like that:
-------------------------------------------------------------------------
| ID | name | description | price | option | image | size | explanation |
-------------------------------------------------------------------------
| 1 | test | some desc | 50 $ | opt. 1 | img1 | 30 | |
| | | | | opt. 2 | img2 | | |
| | | | | opt. 3 | img3 | | |
| | | | | | img4 | | |
| | | | | | img5 | | |
| | | | | | img6 | | |
Right now, the above table gets populated in every field, but it's multiplied, so I don't get only 6 rows, but 24.
I did a lot of JOINS, I'm not a beginer, which is even more frustrating, but it's the first time I try to do that, a select from multiple tables with different columns and unknown number of rows.
package_option and package_images looks like that:
-------------------------------------
| ID | package_id | option / image |
-------------------------------------
| 1 | 1 | opt. 1 / img 1 |
| 2 | 2 | opt. 2 / img 2 |
..... etc
so I don't know how many rows I'll have.
Thank you in advance for t

Update table from another table throught intermediate table Mysql

I have the next table setup, two tables related by an intermediate table, like this:
Client
| client_id | ...|field_X |
| 1 | ...|value1 |
| 2 | ...|value2 |
| 3 | ...|value3 |
Project
| project_id | ...|field_X |
| 1 | ...| |
| 2 | ...| |
| 3 | ...| |
| 4 | ...| |
| 5 | ...| |
| 6 | ...| |
| 7 | ...| |
client_project
| client_id | project_id|
| 1 | 2 |
| 1 | 3 |
| 2 | 4 |
| 2 | 5 |
| 3 | 6 |
| 3 | 7 |
The field_x in the table project is new and i have to fill it with the data from table client to get approximately something like this:
Project
| project_id | ...|field_X |
| 1 | ...| |
| 2 | ...|value1 |
| 3 | ...|value1 |
| 4 | ...|value2 |
| 5 | ...|value2 |
| 6 | ...|value3 |
| 7 | ...|value3 |
i dont know hot to deal with the intermediate table. i have tried this code but it doesnt work.
INSERT INTO project
(field_x)
(select field_x
from
client_project
inner join
client
where client_project.client_id = client.client_id
);
I have the idea of what i have to do but i am not able to translate it into a sql command because of the intermeditate table.Could someone explain how to deal with it?
Thanks in advance.
I assume you already have all entries in the project table but they're missing the Field_X property? So what you need is an update, not an insert
UPDATE project p, client c, project_client pc SET p.Field_X=c.Field_X WHERE p.ID=pc.ProjectID AND c.ID=pc.ClientID
However, be advised that having the same data in two places is not a good practise; if possible always put one fact in only one place.

How to save user's custom input with a list of predetermined item

I have a database which contain a list of items (item)
+----+-----------------------+-------+--------+-------+
| id | name | width | height | depth |
+----+-----------------------+-------+--------+-------+
| 1 | Some_toy | 35 | 28 | 30 |
| 2 | Pepperoni_pizza | 17 | 30 | 35 |
| 3 | Wood_table | 45 | 42 | 57 |
| 4 | Guitar | 26 | 45 | 75 |
| 5 | Awesome_TV | 80 | 35 | 10 |
+----+-----------------------+-------+--------+-------+
On my website, users can select items inside this list to create their own list of item. User's list are stored in the following table user_list_items
+----+--------------+---------+--------+
| id | id_user_list | id_item | number |
+----+--------------+---------+--------+
| 1 | 6 | 3 | 2 |
| 2 | 6 | 5 | 1 |
| 3 | 6 | 7 | 5 |
| 4 | 7 | 7 | 3 |
| 5 | 9 | 3 | 1 |
+----+--------------+---------+--------+
But, because my list cannot contain every item in the world, I want to allow users to add a custom item.
My problem is that I don't want to store users custom items inside my table item because this table contains the item displayed by default.
However, If I don't save custom items inside my table item, I still must save them somewhere else. So I've created another table custom_item which is an exact replica of item.
With this solution, I've added a foreign key id_custom_item in my table user_list_items which give the following
+----+--------------+---------+----------------+--------+
| id | id_user_list | id_item | id_custom_item | number |
+----+--------------+---------+----------------+--------+
| 1 | 6 | 3 | 0 | 2 |
| 2 | 6 | 0 | 25 | 1 |
| 3 | 6 | 7 | 0 | 5 |
| 4 | 7 | 7 | 0 | 3 |
| 5 | 9 | 3 | 0 | 1 |
+----+--------------+---------+----------------+--------+
And now I have a problem with user_list_items because can link to item or to custom_item and it seems like a very bad practice.
My question is, how could I save user's custom input with a list of predetermined item ?
Sorry this question is not very well formulated but I couldn't find any other way to express it.
If the objection to storing custom items in item table is just that the contents are displayed by default, I'd add a column set to 'Y' or 'N' to the table and add that column to the WHERE clause of the query that populates the default list, eg AND default_flag = 'Y'

how to insert average of a query into mysql table

I am trying to get average of latency for each items that holds into two separate mysql table. Let me more clarify that I have two mysql tables as below,
table: monitor_servers
+-----------+-----------------+
| server_id | label |
+-----------+-----------------+
| 1 | a.com |
| 2 | b.com |
+-----------+-----------------+
table: monitor_servers_uptime
+-------------------+-----------+-----------+
| servers_uptime_id | server_id | latency |
+-------------------+-----------+-----------+
| 1 | 1 | 0.4132809 |
| 3 | 1 | 0.4157769 |
| 6 | 1 | 0.4194210 |
| 9 | 1 | 0.4140880 |
| 12 | 2 | 0.4779439 |
| 15 | 2 | 0.4751789 |
| 18 | 2 | 0.4762829 |
| 22 | 2 | 0.4706681 |
+-------------------+-----------+-----------+
Basically, each domains associated with the same id_number in both tables. While I am running the query below, getting average of each items.
select monitor_servers.label, avg(monitor_servers_uptime.latency)
from monitor_servers,monitor_servers_uptime
where monitor_servers.server_id = monitor_servers_uptime.server_id
group by monitor_servers.server_id;
The query ended up,
+---------------------+-------------------------------------+
| label | avg(monitor_servers_uptime.latency) |
+---------------------+-------------------------------------+
| a.com | 0.41393792995 |
| b.com | 0.47551423171 |
+---------------------+-------------------------------------+
My questions are doing am i in wright way while getting average of the each items and how can i insert new average result of each items into a new column on table monitor_servers ? And also what happens if some of latency rows are NULL ?
**Edit : What i am trying to achieve in one query result is **
+-----------+----------+------------------+
| server_id | label | avg. |
+-----------+----------+------------------+
| 1 | a.com | 0.41393792995 |
| 2 | b.com | 0.47551423171 |
+-----------+-----------------------------+
Thanks in advance,
Your calculation seems to be correct.
You could add another column to the monitor_servers using sql:
ALTER TABLE monitor_servers ADD avg_latency DEFAULT 0.0 NOT NULL
For doing the AVG calculation check this answer.

Class attendance record format SQL Query [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
MySQL dynamic cross tab
I have student_record table
-------------------------------------------------------------------
student_id | semester | schoolyear| name | section |
-------------------------------------------------------------------
1 | 1st Semester| 2011-2012 | john | c21 |
2 | 1st Semester| 2011-2012 | eric | c21 |
3 | 1st Semester| 2011-2012 | mark | c21 |
and attendance table
-------------------------------------------------------------------
attendance_id | stud_id | week |
-------------------------------------------------------------------
1 | 1 | 02/04/2012 |
2 | 2 | 02/04/2012 |
3 | 3 | 02/04/2012 |
4 | 1 | 02/11/2012 |
5 | 2 | 02/11/2012 |
6 | 1 | 02/18/2012 |
7 | 2 | 02/18/2012 |
8 | 3 | 02/18/2012 |
And I want to achieve this output using sql.
-------------------------------------------------------------------
student_id | name | 02/04/2012 | 02/11/2012 | 02/18/2012 |
-------------------------------------------------------------------
1 | john | present | present | present |
2 | erik | present | absent | present |
3 | mark | present | present | present |
this is very vague to me, can anyone help?
I tried this, but didn't work.
Select week,
[02/28/2012],
[02/29/2012]
From attendance
group by student_id
Regardless of the database you are using, the concept of what you are trying to achieve is called "Pivot Table".
Here's an example for mysql:
http://en.wikibooks.org/wiki/MySQL/Pivot_table
Some databases have builtin features for that, see the links below.
SQLServer:
http://msdn.microsoft.com/de-de/library/ms177410.aspx
Oracle:
http://www.dba-oracle.com/t_pivot_examples.htm
You can always create a pivot by hand. Just select all the aggregations in a result set and then select from that result set.
Also check this link, you will get your answer provided by MGA...