Hi I have a table of data:
ID Type FROM TO
a1 A 0 15
a1 B 15 25
a1 A 25 30
a1 A 30 65
a1 B 65 67
which I would like to query. The result I would like is to see what metres fall within a range, as below:
ID Type 0-10 10-20 20-30 30-40 40-50 50-60 60-70
a1 A 10 5 5 10 10 10 5
a1 B 5 5 2
Can I use the IDS/SID functions or is there already a function that can do this query.
Thank you
ID Type FROM TO
a1 A 0 15
a1 B 15 25
a1 A 25 30
a1 A 30 65
a1 B 65 67
which I would like to query. The result I would like is to see what metres fall within a range, as below:
ID Type 0-10 10-20 20-30 30-40 40-50 50-60 60-70
a1 A 10 5 5 10 10 10 5
a1 B 5 5 2
Can I use the IDS/SID functions or is there already a function that can do this query.
Thank you
Code:
drop table #temp
create table #temp (ID varchar(5),[Type] varchar(20), from_m numeric, to_m numeric)
insert into #temp(ID,[Type],from_m,to_m)
values('a1','A','0','15')
insert into #temp(ID,[Type],from_m,to_m)
values('a1','B','15','25')
insert into #temp(ID,[Type],from_m,to_m)
values('a1','A','25','30')
insert into #temp(ID,[Type],from_m,to_m)
values('a1','A','30','65')
insert into #temp(ID,[Type],from_m,to_m)
values('a1','B','65','67')
select * from #temp