You aren't big on providing information today. Given the excellent ddl and sample data provided by Neeraj can you tell what the relationship between these tables is?
I think it is something like this, but I don't know what the last one would be.
Select *
From #a a
join #B b on b.ENTERPRISE_MAIN_CODE = a.ENTERPRISE_MAIN_CODE and b.ENTERPRISE_SUB_CODE = a.ENTERPRISE_SUB_CODE
join #C c on ???
Your output continues to be very elusive. The description is very confusing.
As a side note, you really should use datetime datatypes when storing datetime information. Storing them as bigint is a waste of space and makes everything far more difficult to work with.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/