use Research
go
DECLARE @TableName varchar(255);
CREATE TABLE #GetRecordingTempTable([TableName] varchar(255) NOT NULL, [mrs] date);
DECLARE Table_Cursor CURSOR FOR
--包含有列‘sigdate’的表
select a.[name] 表名 from sysobjects a,
(
select [id],count(*) b from syscolumns
where [name] ='sigdate'
group by [id]
)
b where a.[id]=b.[id]
order by name asc
OPEN Table_Cursor;
FETCH NEXT FROM Table_Cursor INTO @TableName;
WHILE(@@FETCH_STATUS=0)
BEGIN
EXEC('insert into #GetRecordingTempTable(TableName,mrs) SELECT '''+@TableName+''', max(sigdate) FROM ['+@TableName+'];');
FETCH NEXT FROM Table_Cursor INTO @TableName;
END
select A.*,B.rk from #GetRecordingTempTable A inner join Research..datelist_tradingdate_daily B on mrs=sigdate order by mrs desc
CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;
DROP TABLE #GetRecordingTempTable;
GO