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 |  
                                    | richardlawYak Posting Veteran
 
 
                                        68 Posts | 
                                            
                                            |  Posted - 2013-05-04 : 15:14:32 
 |  
                                            | HiI have a table of classes. Each class runs only once a week, and the classes table stores the day it runs as an INT (1 = Mon, 2 = Tue, … 7 = Sun).I now need to create a temp table that list all the classes that take place within a date range (like  a calendar of events). So for example, if the first class runs even Monday, and my date range is over 4 weeks and 3 days, I would expect to see in my temp table 5 rows (date, classID) – assuming one of the 3 days is a Monday.I assume I would need a loop of some kind that filters each date in the date range to check if a class runs on that day, if so, add a row to the temp table with the date and classID; if not, move on to the next class before moving on to the next day (date + 1 day).I’d really like to find a way that does not require loops. The method above seems very process intensive. I’m new to TSQL, but looping like that just feels clumsy.Any ideas?Thanks as always |  |  
                                    | MuMu88Aged Yak Warrior
 
 
                                    549 Posts |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts |  |  
                                |  |  |  |