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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Conditional Truncate

Author  Topic 

psystems
Starting Member

8 Posts

Posted - 2005-08-08 : 16:35:51
Hi,

I have a temp table containing 3 fields:
table name, record count 1, record count 2.

I want to loop thru this temp table and if record count 1 = record count 2 then I want to TRUNCATE TABLE tablename .

How can I do this without having a truncate statement for every table name?

Thanks,

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-08-08 : 16:48:48
you'll have to build a dynamic sql to generate the command to truncate the different tables.

I'm sure there are examples of writing dynamic sql on the main sqlteam page if you are not familiar with how to do this.



-ec
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-09 : 01:46:00
Run this

Select 'Truncate Table '+tablename from temptable where recordcount1=recordcount2

Copy the result and paste in QA and run

Madhivanan

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

- Advertisement -