| 
	
 | 
 Posted by Erland Sommarskog on 10/22/05 17:17 
rola (rong.guo@gmail.com) writes: 
> I think i got myself a little bit confused... As I always use the 
> tables created by our DBA, I am not very familiar with 
> creating/altering tables, as well as the primary key (sorry). Here is 
> what i do now every month: 
>  
> --At the end of September 
> select A, B (A B would change every month) 
> into customer_20050930 
> from table_A (already in our database and will be updated monthly) 
> group by A, B 
>  
> --At the end of October 
> select A, B (A B would change every month) 
> into customer_20051031 
> from table_A (already in our database and will be updated monthly) 
> group by A, B 
>  
> I am wondering how I can apply what you suggested to my current query? 
> Could you please show me the query? 
  
 
If the tables can look different from month to month, then it is a little 
more tricky to use one table with month as key. Of course, you can alter 
the table to add or drop columns, but this may not be feasible. 
 
I would suggest that the best is to use any text editor with a find-replace 
functon to replace the strings. Since the queries change from to month, you 
need to edit anyway. 
 
The alternative is to use dynamic SQL, but that would make the script more 
difficult to maintain. 
 
--  
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se 
 
Books Online for SQL Server SP3 at 
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
 
  
Navigation:
[Reply to this message] 
 |