I am trying to check a table is empty and if it is empty drop the table in dynamic sp but my query is not working.2 methods i have tried
I am checking if a coloumn is null or empty will drop the table
- set @dropempty='IF EXISTS (SELECT * FROM ' + @table+ ' WHERE city IS NULL OR country= '' '' ) DROP TABLE ' + @table
- select @dropempty
- EXEC sys.sp_executesql @dropempty
2nd methods row check
- set @dropempty='IF EXISTS (SELECT 1 FROM ' + @table+ ''') DROP TABLE ' + @table+''
- EXEC sys.sp_executesql @dropempty
Pankajkumar PatelPosted Sep 7, 2020, 9:28 AM
Laxmidhar SahooPosted Sep 5, 2020, 7:22 AM
Nisha RegilPosted Sep 4, 2020, 10:58 PM
Sujeet RamanPosted Sep 4, 2020, 10:48 PM
EXEC sys.sp_executesql @dropempty
Nisha RegilPosted Sep 4, 2020, 8:29 PM