469,609 Members | 1,687 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Dynamic Union of Tables

Hi I am developing an application in C# with MS SQL at backend .
My database has tables corressponding to every month named JAN2008 ,FEB2008 . I allow user to enter From Date and To Date from two calenders on the front end. Now i want to write a query which would dynamically Union all the tables which lie between the selected dates of calenders and give me only those records in the union which satisfy any particular condition.
Hope you would help me with this problem !
Mar 6 '08 #1
2 3463
ck9663
2,878 Expert 2GB
Hi I am developing an application in C# with MS SQL at backend .
My database has tables corressponding to every month named JAN2008 ,FEB2008 . I allow user to enter From Date and To Date from two calenders on the front end. Now i want to write a query which would dynamically Union all the tables which lie between the selected dates of calenders and give me only those records in the union which satisfy any particular condition.
Hope you would help me with this problem !
Actually you have to build the dynamic query (sqlstring) on your front-end, so this is more of a C# question than an MS-SQL.Try posting it in C# forum. I'm not much of a C# programmer. I'll try to help you with a pseudo-code.

1. Using the date1 and date2 from the textbox and store it in variables but hardcode it as the first day of that month.

2. Loop while date1 <= date2

3. Inside the loop, build your query.

4. Execute your query.

I hope I'm making sense :)

-- CK
Mar 6 '08 #2
Hi MasterBlaster

With the tables you have at the moment, the easiest solution is to use the C# approach suggested. However, I would suggest that, if possible, you look into changing your tables so that you have a "DateEntered" column. Then you don't have to change the database schema every month, and the query becomes a simple "BETWEEN" statement.

HTH
Mar 7 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Ninan Thomas | last post: by
3 posts views Thread by Paradigm | last post: by
2 posts views Thread by Gerry | last post: by
2 posts views Thread by mattytee123 | last post: by
4 posts views Thread by Alfonso Morra | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.