Create Procedure P_GradeCourse
@Course varchar,@Table varchar
as
set @StrSql as varchar(255)
set @strsql1 as varchar(2000)
set @TableName as varchar(100)
declare Cur_Table Cursor for
select name from sysobjects where name like 'Course%' and Satus>1
open Cur_table
fetch next from Cur_table into @TableName
while @@Fetch_status=0
Begin
set StrSql='select Grade,Course from '+@strSql+' where Course='+@Course+''
set @Strsql1=@Strsql1+' Union all '+@StrSql
fetch next from Cur_table into @TableName
end
select Grade,Course from Test1 where Course=@Course
union all
select Grade,Course from Test2 where Course=@Course
union all
select Grade,Course from Test3 where Course=@Course
union all
select Grade,Course from Test4 where Course=@Course
union all
select Grade,Course from Test5 where Course=@Course
union all
select Grade,Course from Test6 where Course=@Course