0

I have this SQL query

SELECT a.name, a.state_desc, b.start_date, b.modify_date, b.percentage_complete  
FROM sys.databases AS a  
INNER JOIN sys.dm_database_copies AS b ON a.database_id = b.database_id  
WHERE a.state = 7;  

I want to extract the table name from the query which in this case is the databases

How can I do it? I am mostly concerned with fetching the database table name immediately after the From clause, any guidance how can I do it?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
niim
  • 13
  • 5
  • 1
    Does this answer your question? [How to extract table names and column names from sql query?](https://stackoverflow.com/questions/35624662/how-to-extract-table-names-and-column-names-from-sql-query) – Dale K May 12 '20 at 22:25
  • In general you could just chuck the SQL in a throw away proc and then look at `sys.sql_expression_dependencies` - but annoyingly this doesn't work for `sys.databases` - maybe it doesn't record dependencies on system objects – Martin Smith May 12 '20 at 23:10

0 Answers0