create procedure query @flag varchar(10) AS
begin
if @flag = 'year'
begin
select year ,count(field1) from table group by year
end
else
if @flag = 'month'
begin
select month,count(field1) from table group by month
end
else
if @flag='day'
begin
select day ,count(field1) from table group by day
end
end