Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | nebula81Starting Member
 
 
                                        4 Posts | 
                                            
                                            |  Posted - 2013-04-08 : 05:01:33 
 |  
                                            | Hi,I still new with SQL server 2005. i have problem to create view.I have 2 tables. Table 1 consist of Name, StartDate & EndDate. Table 2 is just a list of date (where i want to calculate how may records falls in these date)For Example Table 1:Name StartDate EndDateSarah 1/1/2013 1/2/2013Mike  1/2/2013 1/4/2013John  1/1/2013 1/2/2013Jill  1/2/2013 1/4/2013Table 2:1/1/20131/2/20131/3/20131/4/2013The result should be like this:Date     NoOfRecord1/1/2013   21/2/2013   41/3/2013   21/4/2013   2I don't know how to write SQL to come out with this result.Please helpThank you |  |  
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-04-08 : 05:31:44 
 |  
                                          | SELECT c2.Dates, COUNT(*) cntFROM Table1 c1JOIN Table2 c2 ON c2.Dates BETWEEN c1.StartDate AND c1.EndDateGROUP BY c2.Dates |  
                                          |  |  |  
                                    | nebula81Starting Member
 
 
                                    4 Posts | 
                                        
                                          |  Posted - 2013-04-08 : 05:43:25 
 |  
                                          | Hi bandi,what is c1 and c2?tq! |  
                                          |  |  |  
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-04-08 : 06:10:23 
 |  
                                          | quote:c1 and c2 are alias names for respective tables--ChanduOriginally posted by nebula81
 Hi bandi,what is c1 and c2?tq!
 
 |  
                                          |  |  |  
                                    | nebula81Starting Member
 
 
                                    4 Posts | 
                                        
                                          |  Posted - 2013-04-08 : 23:27:57 
 |  
                                          | Hi bandi,it works! thank a lot!   |  
                                          |  |  |  
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-04-09 : 00:18:41 
 |  
                                          | quote:Originally posted by nebula81
 Hi bandi,it works! thank a lot!
  
  --Chandu |  
                                          |  |  |  
                                |  |  |  |