hey guys,
right... trying to do a stored procedure to bring back a table showing a count of members who have certain attributes etc.....
i can't seem to figure out how to stick all the values in one row... the reason is at present i'm doing a different insert statment for each one.... each column has different 'where' criteria to match... example script below......
create table #table1 (
fm_world int,
bifm int,
third_party int,
fm_daily int,
east int,
home_counties int,
international int,
london int,
midlands int,
north int,
scotland int,
south int,
south_west int,
charity int,
education int,
healthcare int,
retail int,
building_serv int,
health_safety int,
info_manag int,
sig_international int,
procurement int,
rising_fm int,
security int,
sustain int,
workplace int
)
--FM World
insert into #table1 (fm_world)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 1322
--BIFM
insert into #table1 (bifm)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 2191
-- 3rd Party
insert into #table1 (third_party)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 1326
-- FM Daily
insert into #table1 (fm_daily)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 2843
select * from #table1
drop table #table1
apologies for massive script!!
any ideas how to get it into one row?
right... trying to do a stored procedure to bring back a table showing a count of members who have certain attributes etc.....
i can't seem to figure out how to stick all the values in one row... the reason is at present i'm doing a different insert statment for each one.... each column has different 'where' criteria to match... example script below......
create table #table1 (
fm_world int,
bifm int,
third_party int,
fm_daily int,
east int,
home_counties int,
international int,
london int,
midlands int,
north int,
scotland int,
south int,
south_west int,
charity int,
education int,
healthcare int,
retail int,
building_serv int,
health_safety int,
info_manag int,
sig_international int,
procurement int,
rising_fm int,
security int,
sustain int,
workplace int
)
--FM World
insert into #table1 (fm_world)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 1322
--BIFM
insert into #table1 (bifm)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 2191
-- 3rd Party
insert into #table1 (third_party)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 1326
-- FM Daily
insert into #table1 (fm_daily)
select count(*) from individual i
left join member m on m.individual_ref = i.individual_ref
left join attribute a on a.individual_ref = i.individual_ref
where m.member_status = 33
and m.join_date is not null
and m.leave_date is null
and a.attr_code_ref = 2843
select * from #table1
drop table #table1
apologies for massive script!!
any ideas how to get it into one row?