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 |
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2013-05-20 : 05:16:13
|
Hi All,I have a table name: TempTablesListcolumn: Tablesselect tables from TempTablesList will return me a list of result:-drop table temp_AAAAdrop table temp_BBBBdrop table tblArch_Abudrop table tblArch_AliHow can i execute this drop table value to drop all the tables listed in the tables at TempTableList table?Please advise.Thank you.Regards,Micheale |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-20 : 05:47:49
|
you have to run as dynamic statement....--try this..DECLARE @SQL VARCHAR(MAX) = ''SELECT @SQL = @SQL +'; ' + tables FROM TempTablesList;SET @SQL = STUFF(@SQL, 1, 2, '')EXEC (@SQL)--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-20 : 07:14:14
|
just do a statement likeSET NOCOUNT ONGOSELECT 'DROP TABLE ' + TablesFROM TempTablesList choose output as text option in SSMS and execute the above queryin output tab copy the output obtained which will be list of drop statements and paste it into a new window connecting to required db and execute.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-20 : 07:23:00
|
Hi visakh,I think OP has "DROP Statements" in the column Tables of TempTableList (OPs title is statement stored in a table)--Chandu |
|
|
|
|
|