I have a table with TABLE_NAME and ROW_COUNT, this has around 200+ table names populated. I want to be able to find the MAX (LAST_UPDATED) value from each table displayed, so my output will then have TABLE_NAME,ROW_COUNT,LAST_UPDATED
I have attempted some SQL Cursor, but as i've never used this before, i'm finding it difficult to use the variable to perform a query to return the data i want.
i know this is not correct but was my best attempt
DECLARE @TableName as VARCHAR(256) DECLARE @updated_timestamp as DATETIME DECLARE tablenamefromcursor CURSOR FOR SELECT OPEN @tablenamefromcursor FETCH NEXT FROM tablenamefromcursor INTO @TableName, @RowCount WHILE @@FETCH_STATUS = 0 BEGIN UPDATE #tmpRowCount SET updated_timestamp = (SELECT MAX(updated_timestamp) FROM @TableName) FETCH NEXT FROM @tablenamefromcursor INTO @TableName, @RowCount END CLOSE