I am trying to create a SQL Statement that will return the table schema name and the if the data was created a day ago.
This will create the SQL Statement with the table schema name:
DECLARE @SqlStatement VARCHAR(MAX)
SELECT @SqlStatement =
COALESCE(@SqlStatement, '') + 'DROP TABLE [TMP].' + QUOTENAME(TABLE_NAME) + ';' + CHAR(13)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'TMP'
PRINT @SqlStatement
How do I add in the where clause if the table was created a day ago all in the same statement?
The
create_date
field is stored insys.tables
. You can then join back tosys.schemas
to get the schema name.Something like this: