...
P.S. I'm attaching an excel document with a sample of the source tables and sample of the desired output.

Thanks
This doesn't really look for me to be a problem of C# , but more that looks me to be a problem of a correct sql query