0

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.

4

1 回答 1

1

尝试这个

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

阅读此处了解更多信息 链接

于 2012-07-18T09:57:37.990 回答