Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Help with Complex Query

$
0
0

Hi

I have to write a query that looks like so:

Cust ID  |  Prgm1  | Desc1  |  Date1  |  Prgm2  |  Desc2  | Date2  | PrgmN  | DescN  | DateN

----------------------------------------------------------------------------------------------------------------------

100           X             X Pgm    1/1/10     Y             Y Pgm    2/1/10   Z              Z Pgm  1/3/11

101           X             X Pgm    1/1/10                                              Z               Z Pgm   1/3/11

The query looks in a customer table and then in a program table for the each program the customer has a record for and then displays the data for each customer, along with the records for the program the customer participates on. The number of programs to query is limited and will be known at the outset. However, the customer may or may not participate in all the programs. In the case the customer does not participates in the program, an empty string will suffice. 

I tried a number of different approaches but I am getting nowhere; my latest attempt was to do a sort of flat query where each group of items related to a Program where the result of a JOIN. That works, but the performance is terrible.

Any help will definitely be appreciated.

Hector


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>