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 2005 Forums
 Transact-SQL (2005)
 I can't work out what is wrong with this code??

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2008-12-12 : 05:36:45
Heeeeeeeelp...........
I have this code below, and its not working. I have checked the statements, and they execute when I run them individually, but not as part of this while loop. Can anyone see whats wrong as I cannot see the woods for the trees!!!!


DECLARE @count INT
, @Rowcount INT
, @SQL NVARCHAR(MAX)


SET @count = 1

SELECT @Rowcount = COUNT(1) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'crdm'
SELECT @Rowcount

-- DROP ALL TABLES
WHILE @count <= @Rowcount
BEGIN
SELECT TOP 1 @SQL = 'IF OBJECT_ID(''' + 'crdm.' + TABLE_NAME + ''',''U'') IS NOT NULL BEGIN DROP TABLE crdm.' + TABLE_NAME +' END'
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'crdm' --AND TABLE_NAME NOT LIKE 'Header%'
EXEC sp_executesql @SQL

SELECT @count = @count + 1
END


Hearty head pats

Bex
Aged Yak Warrior

580 Posts

Posted - 2008-12-12 : 05:42:53
Ok, please don't reply. Now its working?!?!?!?!?!

Hearty head pats
Go to Top of Page
   

- Advertisement -