Reputation: 1480
I want to save entries to a database table depending on the DateTime entered. I have a different model and partial view for each month in the year. Users can create events, I want the events to be saved to the corresponding month table in the db so I can return it to the correct view.
So I need some sort of if statement that says 'if the month value of the entered DateTime is x save to tabel x, if y save to y' and so on.
The user will navigate from month to month and pick dates from a html table styled like a calendar, so the entries need to be inserted to the section of the calendar that corresponds to the datetime. This is just to explain why I need this functionality.
If someone can reccomend a more elegant and functional method of achieving this, go right ahead!
I'm sorry I don't have code to post, I have tried a number of ways and failed. I will post code tomorrow morning when I'm at my computer, but this seems quite simple and I'm very new to this lark so if someone could shed light now, that would be great.
Thanks in advance!
Upvotes: 1
Views: 519
Reputation: 10327
Don't break it out into 12 separate tables. Store them in a single table. You could create a computed column that tells you the month number by calculating it from the DateTime value you're already storing. If your REALLY need to, you can create 12 views off of this table rather easily but I'd take the approach of adding time parameters to your query's WHERE clause. Make sure you index on the DateTime column.
Upvotes: 1