Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness Meta

Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs

declare @t table(Id int, tagNo int, TermNo int)
insert @t values
(1,1000,2), (2,1000,3), (3,1000,7), (4,1002,1), (5,1002,10)

;with a as
  select max(TermNo)-1 TermNo, TagNo
  from @t 
  group by TagNo
b as
  select 1 n, TagNo, TermNo
  from a
  union all
  select n+1, TagNo, TermNo
  from b 
  where n < TermNo
c as
  select n, TagNo 
  from b
  select TermNo, TagNo
  from @t
select * from b

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results