I have wasted my 2 whole days to trying to resolve this issue, Now I am going out of my mind, I need an urgent Help, The Issue is, I Have To Tables
Table: Sales, SalesId is primary key
---------------------------------------------------
SalesId | SalesDate | Customer| Discount | Remarks
---------------------------------------------------
1 | 01/01/2012| John | 15 | NULL
2 | 01/01/2012| Peter | 25 | NULL
3 | 01/01/2012| Micheal | 35 | NULL
Table: SalesBody, SerialNo is primary key
and SalesId is foreign key
---------------------------------------------------
SerialNo | SalesId | Product | Quantity | Rate
---------------------------------------------------
10 | 1 | Pencil | 18 | 20
11 | 1 | pen | 200 | 60
12 | 1 | Rubber | 150 | 10
13 | 1 | Paper | 500 | 2
14 | 2 | Mouse | 15 | 190
15 | 2 | KeyBoard | 10 | 600
16 | 2 | Monitor | 5 | 2000
17 | 3 | Mobile | 2 | 15000
Now I want to make a query which can make the result like following
----------------------------------------------------------------------------
SalesId | SalesDate | Details | Amount
----------------------------------------------------------------------------
1 | 01/01/2012 | Sold: Pencil x 18 @ 20, Pen x 200 @ 60| xxxxxxx
| | Rubber x 150 @ 10, Paper x 500 @ 2 |
2 | 01/01/2012 | Sold: Mouse x 15 @ 190, Keyboard x 10 |
| | @ 600, Monitor x 5 @ 2000 | xxxxxxx
3 | 01/01/2012 | Sold: Mobile x 2 @ 15000 | xxxxxxx
I have tried different techniques eg. Coalesce, Stuff, For XML PATH('')
I could not Concatenate the Detail String.