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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 return value from varied tables

Author  Topic 

papaneil
Starting Member

2 Posts

Posted - 2011-12-19 : 23:09:27
hi, we have an application with an sql back end that has several "log" tables. Each month has its on table devoted to these "logs". example, clog201112. i am trying to write a stored procedure that i will put into reporting services that will allow the user to specify a time frame. i know how to do this with just one table, or one table with a join or two, but how can i do this with these types of tables? thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-20 : 00:11:32
why do you need seperate table for each month? isnt it enough to use single table with month column indicating which month the data came?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-20 : 02:34:00
You need to use dyanamic sql by calculating year and month value from current date

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-20 : 03:16:14
or even if its same table you can organise them into different file groups by applying partitioning in case query performances are low

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

papaneil
Starting Member

2 Posts

Posted - 2011-12-20 : 05:23:47
i do not control the structure of the database; this is not a custom app. usually there are over 3 million records for each month. i am sure this is the reason for the multiple tables.

i figured i would need to base the procedure off the current date, but how do i account for the varying table names: clog201101, clog 201102, clog201103, clog201104, clog201105, clog201106, etc.

also, there is a field in each table, evdate, that displays the exact time and date when the record was entered. thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-20 : 06:55:29
you have to make use dynamic sql for that. for getting time and date of entry use GETDATE() function

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-12-20 : 06:59:54
or you could:

Create a partitioned view over the tables and have a job that will recreate the view at the start of each month?



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-20 : 07:52:27
clog

priceless



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -