473,543 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Union of Tables

2 New Member
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 3662
ck9663
2,878 Recognized Expert Specialist
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
Brad Orders
21 New Member
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 "DateEntere d" 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

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

Similar topics

1
2364
by: Ninan Thomas | last post by:
I am posting this to two not so directly related groups. But i feel it belongs to both. I am trying to create a database at runtime in Berkeley DB and insert and retrieve values from it. So I cannot pre compile the schema into a C++ struct, as explained in the sleepycat documentation. 1) What is the most effecient way to do this? (This is a...
10
12816
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following SQL commands will return the same result but one of my friends don't think so. He said "QUERY 1" will return 1 unsorted record (ROWNUM < 2 ) first...
4
8059
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure creates a string of custom SQL statement and returns this string back to the main stored procedure. This SQL statements work fine on there own....
3
3548
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID from letdata UNION SELECT as ID FROM MEMODATA; I get an ODBC error. The same query runs when the backend files are MDB files and it runs with...
2
10738
by: Gerry | last post by:
I am relatively new to DB2 and having a problem with a simple union statement. Running Db2UDB version 8.1.1 on Aix 5.1 The union and union all SQL statements I am running produce the same results. No duplicates are being eliminated in the union. To verify, I ran SQL with union statements against system tables.
2
4329
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code Count 1234 1 2468 1 1234 1 2468 1
4
1506
by: Alfonso Morra | last post by:
Hi, I'm trying to write a simple generic container. I have the ff: typedef union { long int_val ; char* string_val ; double dbl_val ; void* vptr_val ; }Element ;
7
3373
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always either AND or OR but never mixed together. We can use Northwind database for my question, it is very similar to the structure of the problem on the...
0
2316
by: Alan Woods | last post by:
Hi, I need to query on some data. The data is from SMS2003, stored in SQL2005, all on a Windows2003 server. I write a few queries, but I consider myself an SQL beginner at best. Normally, I write simple queries like "select column1, column2, column4 from a_table where column2 = 'something'". That's about 90% of my writing ability. Here's...
0
7584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3385
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
952
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
626
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.