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.
| Author |
Topic |
|
dnaes
Starting Member
3 Posts |
Posted - 2007-12-15 : 21:33:29
|
| i have multiple tables that we have created for our data warehouse that begin with 'rej'. these are the reject tables and need to be truncated before our etl process begins. i have written a loop statement but cannot pass the variable @rej_nm to the truncate table statement. here's my logic.1> create table variable @rej_tbl(nm, identity column)2> load all tables from sysobjects that begin with 'rej' into @rej_tbl3> create/load @rej_nm from @rej_tbl (first table name that needs to be truncated)4> loop thru and truncate each @rej_nm value. CANNOT get statement to work:truncate table @rej_nmplease advise..thanks y'all!! |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-12-15 : 21:41:57
|
| use dynamic sql._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-12-15 : 23:08:28
|
exec('truncate table ' + quotename(@rej_nm)) elsasoft.org |
 |
|
|
dnaes
Starting Member
3 Posts |
Posted - 2007-12-16 : 08:56:36
|
| exec('truncate table ' + quotename(@rej_nm))worked great...thank you! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|