Join on LINQ relative to check list boxes - asp.net

I have 3 tables.
person
equipment
relation between person and equipment
I have a page with a search button and a checklistbox that binds with the equipment. I want the user to be able to select one or more check list and then show people associated with the selected equipment.
-------------------------
table1
p_famil p_code
ali 1
reza 2
mohamad 3
kazem 4
---------------------------------
table 2
e_code e_title
1 home
2 car
3 job
--------------------------------
table 3
er_eq_code er_per_code
2 1
3 1
1 2
1 4

Related

how to make select query for Infinite level of tree, using a recusive method

I want to make an SQL query that can select all the children trees that belongs to the chosen parent for example:
the foolowing picture will explain.
if I choose parent hot i must get{tea,green tea, lemon tea,reg tea,cofee,espresso,cappuchino,late}
if I choose "juice" i get also all children belongs for it {mango,orange,lemonade}
I think it should be a recusive select method that can call it self untill all levels of sub childrens are called.
(https://i.stack.imgur.com/h5FGc.png)
DRINK-hot-tea-green,reg,lemontea
| |_Coffe-Cappuchino,espresso,late
|
|____cold-shake-coktail,strawbery,banann
|__Juice-mango,orange,...
|__water-still,sparkling,flavoured,..
it should be a recursive select method that can call itself until all levels ofsub-childrenn are called.
the table can be
id name ref
1 drink 0
2 cold 1
3 hot 1
4 tea 3
5 coffe 3
6 shake 2
7 juice 2
8 water 2
9 espreso 5
10 capucino 5
11 late 5
12 mango 7
13 coktail 6
14 still 8
15 sparkling 8
table

Create a calculated field in tableau

I have a set of data in the following format:
Items Shipped | Month
A 1
B 1
C 1
D 2
E 2
F 3
G 3
H 3
I would like to show the count of items shipped each month using a calculated field in Tableau.
Item_Count | Month
3 1
2 2
3 3
Any Suggestions?
You should probably have a look on the Tableau page for their basic tutorials:
https://www.tableau.com/learn/training
Drag the [month] pill to row (if it's an actual date, change it to discrete month, otherwise leave it like it is)
Drag the [item_count] to columns, click on it and change it to COUNT or COUNTD depending whether you want the total count or only the distinct elements.

datasets and joins. ASP.net

I have 3 tables. Namely Job_Master,Print_details,Paper_Details.
The Structure of the table is as follows:
Job_Master:
jobno jobname amount
1 A 100
2 B 200
3 C 300
Print_Details id being the PK and jobno being FK
id jobno color
1 1 Cyan
2 1 Red
3 2 Black
4 3 Black
5 3 Green
Paper Details id being the PK and jobno being FK
id jobno Type
1 1 Art Paper
2 1 Photo Paper
3 2 Art Paper
4 3 Copier
5 3 Glossy Paper
I want a write a query in SQL server or perform Dataset operations in ASP.net so as to display the below resultset in the grid view:
Desired Resultset:
jobno jobname printDetails paperDetails amount
1 A CYAN,RED Art Paper,Photo Paper 100
2 B Black Art Paper 200
3 C Black,Green Copier,Glossy Paper 300
is this possible using dataset operations in ASP.net or in a SQL server query. I am using SQL server 2008 R2 as my database and the fromt end has been designed using ASP.net3.5.
Any help on this is much appreciated.Thanks in advance.
Try this
SELECT DISTINCT a.Jobno, a.jobname, COALESCE(b.color + ', ', '') + b.color,COALESCE(c.type + ', ', '') + c.type
FROM job_master a left JOIN cprint_details b ON a.jobno=b.jobno
left join paper_details c on a.jobno=c.jobno
ORDER BY a.jobno
Read here for more info LINK

Grouping my data in ASP.NET

I hava this table in data base
http://i.stack.imgur.com/r7ECj.jpg
I want to group data in this form
------------ Group 1 -------------
1.FoodGroupName : Milk
a.FoodSubGroup: Milk(type1)
1.food 1
2.food 2
3.food 3
4.food 4
b.FoodSubGroup: Milk(type2)
1.food 1
2.food 2
3.food 3
4.food 4
c.FoodSubGroup: Milk(type3)
1.food 1
2.food 2
3.food 3
4.food 4
--------- Group 2 ------------
2.FoodGroupName : Meat
a.FoodSubGroup: Meat(type1)
1.food 1
2.food 2
3.food 3
4.food 4
b.FoodSubGroup: Meat(type2)
1.food 1
2.food 2
3.food 3
4.food 4
c.FoodSubGroup: Meat(type3)
1.food 1
2.food 2
3.food 3
4.food 4
You could use a query like this:
SELECT fg.FoodGroupName, fsg.FoodSubGroupName, f.FoodName
FROM FoodGroups fg
INNER JOIN FoodSubGroups fsg
ON fg.FoodGroupId = fsg.FoodGroupId
INNER JOIN Foods f
ON fsg.FoodSubGroupId = f.FoodSubGroupId
ORDER BY fg.FoodGroupName, fsg.FoodSubGroupName, f.FoodName
to retrieve data and then output results as you please...
There is several ways to do that kind of thing :
1) you write a single query that will combines the 3 table (using joins) and return a single dataset (like Marco suggested).
eg :
Group SubGroup Food
--------------------------------
Meat Meat1 Food 1
Meat Meat1 Food 2
Meat Meat1 Food 3
Meat Meat2 Food 1
Milk Milk1 Food 1
Milk Milk2 Food 1
Then by using C# code, you group them.
You can do this using very few lines of code (and efficiently) by using GroupBy() linq lambda expression. Have also a look at ToLookUp() extension.
If you are not familiar with them, check this page :
http://code.msdn.microsoft.com/LINQ-to-DataSets-Grouping-c62703ea
In the end you should get a collection of objects that allows you to do the following:
var groups = ...
foreach(var group in groups)
{
//do something with group
foreach(var subGroup in group.SubGroups)
{
//do something with subGroup
foreach(var food in subGroup.Foods)
{
//do something with food
}
}
}
Then it is very easy to fill a treeview or present data using nested repeaters.
2) you write independent queries that will query each table separately. In the end, you get 3 datasets.
Group
-------
1 Meat
2 Milk
SubGroup
---------
1 1 Meat1
2 1 Meat2
3 2 Milk1
4 2 Milk2
Food
----------
1 1 Food 1
2 1 Food 2
3 1 Food 3
4 2 Food 1
5 3 Food 1
6 4 Food 1
Then you use can Group Join linq operator to group them.
In that case, C# will do the joins for you, not sql.
Check here : http://code.msdn.microsoft.com/LINQ-Join-Operators-dabef4e9/description#groupjoin
In the end you will get same result at 1). Both have advantages / disavantages.

Bill of Materials Query

I currently have 2 tables as follows within my database:
Table: SampleProducts
SampleProductsId (PK) Name
1 A
2 B
3 C
4 D
5 E
6 F
7 G
Table: SampleProductsBoms
SampleProductsBomId (PK) ParentId (FK) ChildId (FK) Quantity
1 1 2 3
2 2 3 4
3 4 6 2
ParentId and ChildId both reference SampleProductsId
In English so I can ensure that we are all on the same page:
Product A is made up of 3 of B
Product B is made up of 4 of C
Product D is made up of 2 of F
I would like to create a Stored Procedure / LinQ statement or something which I can use in my MVC 3 c# Web Application which will give me the following table structure / object to use...
Example:
Recursive Query to find the components of B
ProductId Name Quantity
3 C 4
6 F 2
This could go quite deep, so I really do need recursion!
CTE is helpfull for recursing as require in your problem statement check the link
Common Table Expression
or i think following query may also solve your purpose
select components.SampleProductId as productid,components.Name as Name,Quantity
from SampleProductsBOM bom
inner join SampleProducts products
on products.ParentId=bom.ParentId
inner join SampleProducts components
on components.SampleProductId=bom.ChildId
where products.Name='B'

Resources