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