I am trying to check if a particular table name is available under a schema or not using the below query
SELECT name as Database_name,
CASE WHEN HAS_DBACCESS(name) = 1 and
(CASE WHEN state_desc = 'ONLINE' THEN OBJECT_ID( QUOTENAME( name ) + '.[dbo].[Item]','U' )
END IS NOT NULL) THEN 'Y' ELSE 'N' END as Active_Flag
FROM sys.databases where name like 'Aug_%';
Now in addition to the above condition i have to also check the table **item ** has business_date column greater than 2018 onwards and get only those database names. Tried different options, any help or guidance here?
Eg:
DB Name | Table_name | business_date |
---|---|---|
Aug_01 | Item | 01-01-2015 |
Aug_02 | Item | 12-31-2018 |
Aug_05 | Item | 06-10-2013 |
Expected Result
Aug_02
New contributor
Sumathi Ponramar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.