| Author |
Topic |
|
sqlservernovice
Starting Member
9 Posts |
Posted - 2012-04-12 : 16:36:36
|
| all, how can i create a table by name like during runtime. For example, I want to be able to create a table with the name likeschemaname.abcdc_getdate()_stage1eg schemaname.abcdc_12_04_12_Stage1Thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sqlservernovice
Starting Member
9 Posts |
Posted - 2012-04-12 : 17:06:26
|
| i need to create the stage tables so that i can use it in the other process, and drop stage tables at the end of the process. i dont wanna use the temp table as they are huge number of rows to process. what do you suggest. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-12 : 17:33:24
|
| you need to use dynamic sql for thatEXEC 'CREATE TABLE schemaname.abcdc_'+ REPLACE(CONVERT(varchar(11),GETDATE(),103),'/','_') + '_Stage1 (.....'------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-12 : 17:34:41
|
quote: Originally posted by sqlservernovice i need to create the stage tables so that i can use it in the other process, and drop stage tables at the end of the process. i dont wanna use the temp table as they are huge number of rows to process. what do you suggest.
why do you need dates to be in table name?are you creating stage tables for each day seperate? why not add them to same table with a date field to indicate date they belong?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sqlservernovice
Starting Member
9 Posts |
Posted - 2012-04-12 : 17:55:43
|
| i am trying to automate some of the data loading process that is to happen everyday day, and requiremtn is that the stage tables need to be created dyanamically and use the tables to load the data into the target tables and then drop the stage tables after the load is complete. So this is the approach i was wondering to take. any other suggestions, would be great. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-12 : 18:01:25
|
| using stage tables is fine. but question why you need to name them using dates------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2012-04-12 : 18:50:10
|
quote: Originally posted by sqlservernovice i am trying to automate some of the data loading process that is to happen everyday day, and requiremtn is that the stage tables need to be created dyanamically and use the tables to load the data into the target tables and then drop the stage tables after the load is complete. So this is the approach i was wondering to take. any other suggestions, would be great.
Your approach as described is fine, just use static table names to avoid the dynamic SQL that will be required.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-04-17 : 05:01:42
|
| Use a static staging table and truncate it after the data load is overMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-17 : 13:02:08
|
| Just to reiterate, you can have a column to store date inside temporary table to indicate time period of data------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|