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
 Old Forums
 CLOSED - General SQL Server
 Delete empty table using dynamic query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-20 : 09:15:16
balasubramanian writes "My aim is to delete the empth tables in a database for this i used dynamic sql query.

first i created one stored procedure using cursor.

then i created dynamic sql query like this

sqlstr="select count(*) from " + @tablename

then i executed this query

exec(sqlstr)

It's executing fine my problem is to store the value in one variable for check the count. if zero then i will delete the table from database.

how to store the result in one variable.

if you know any other method please send me the code.

sql server version 8.00.194
windows xp

Regards
Bala"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-20 : 09:16:50
Refer this
http://www.nigelrivett.net/SQLTsql/sp_executesql.html

Madhivanan

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

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-03-20 : 10:32:43
or you can try somthing like this??

Set sqlstr= 'If (Select Count(1) From ' + @TableName + ')>0
Begin Delete From ' + @TableName + ' End'


Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page
   

- Advertisement -