I want to delete any development databases that are older than 15 days by comparing the date column in the specified table.
Is there a way to write a DROP database query with a WHERE clause or do I need to do dynamic SQL?
Below is my SQL query:
DROP DATABASE IF EXISTS
WHERE (SELECT ID FROM master.TableName
WHERE Date < DATEADD(DAY, -15, GETDATE())
AND ColumnName1 = 1
AND ColumnName2 = 0)
source
share