February 29, 2012 at 7:14 am
I guess sometimes you need to dance with the Devil 🙂
This is a high-class Bureau-de-Change.
February 29, 2012 at 7:20 am
five_ten_fiftyfold (2/29/2012)
I guess sometimes you need to dance with the Devil 🙂
Again, nope. You could use FOR XML to generate your SQL dynamically then execute it.
e.g.
DECLARE @SQL AS NVARCHAR(MAX);
SELECT @SQL = STUFF(REPLACE(CAST((
SELECT ';' + CHAR(13) + CHAR(10) + 'DROP TABLE ' + QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%71%'
FOR XML PATH('')) AS NVARCHAR(MAX)),';
',''),1,2,'');
PRINT @SQL;
--EXECUTE sp_executesql @SQL;
Creates the following on one of my test servers: -
DROP TABLE [dbo].[TC71_MangledWords];
DROP TABLE [dbo].[TC71_Dictionary]
If I then run the commented out code instead of the PRINT, those two tables would be dropped.
I never learn. . . the forums have replaced "& # x 0 D ;" (no spaces or quotations) with a line break in the code block above. If you add "& # x 0 D ;" (no spaces or quotations) back into the replace, just before the CHAR(13) + CHAR(10) at the end, then it'll work but otherwise it won't.
March 1, 2012 at 3:11 pm
five_ten_fiftyfold (2/29/2012)
I guess sometimes you need to dance with the Devil 🙂
Nah... not for something like this. Cadavre has the right stuff on this one.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 1, 2012 at 5:14 pm
Lol. The right "stuff". You made a punny. 😛
March 1, 2012 at 6:06 pm
😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply