1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Declare @IndId int
Declare IndList CURSOR FOR
select distinct IND_ID from MyDB.UnitData
Declare @Indvar int
Open IndList
FETCH NEXT FROM IndList
into @Indvar;
while (@@FETCH_STATUS = 0)
begin
SET @IndId = @Indvar
Select @IndId ,
Min(ud.Year) as Miny,
Max(ud.Year)as Maxy,
count ( Distinct ud.year) as nmby,
From MyDB.Unit u
Inner Join MyDB.UnitData ud
On ((u.Unit_Id = ud.Unit_id)
and (ud.Ind_id = @IndId ))
FETCH NEXT FROM IndList
end
close IndList
deallocate IndList |