use websitedb declare@tablenamevarchar(50) declare@sqlstrvarchar(300) declare table_cursor cursorfor select o.name from syscolumns c innerjoin sysobjects o on o.id=c.id where o.xtype='u'and c.name='userid' orderby o.name open table_cursor fetchnextfrom table_cursor into@tablename while(@@fetch_status=0) begin set@sqlstr='select '''+@tablename+''' as tablename,* from '+@tablename+' where userid=''qifei''' exec(@sqlstr) fetchnextfrom table_cursor into@tablename end close table_cursor deallocate table_cursor