Yeah, we do the same thing..but it's from scratch every time...What do you do about a header...I add it...and if the query get's hairy, I format the results and select it from a derived tableI have to look into that function you posted.. Select '"Proof_Type"' + ',"Work_Group"' + ',"Status"' + ',"Period Type"' + ',"Proof Year"' + ',"Proof Period"' + ',"Count"' Union All Select '"'+RTrim(IsNull(Proof_Type,''))+'"' + ',"'+RTrim(IsNull(Work_Group_Desc,''))+'"' + ',"'+RTrim(IsNull(Status_Desc,''))+'"' + ',"'+RTrim(IsNull(Period_Type,''))+'"' + ',"'+RTrim(IsNull(Proof_Year,''))+'"' + ',"'+RTrim(IsNull(Proof_Period,''))+'"' + ',"'+RTrim(Convert(Char(15),IsNull(Number_Of_Proofs,0)))+'"' From ( Select 'WH_Proof' As Proof_Type , w.Work_Group_Desc , s.Status_Desc , p.Period_Type , p.Proof_Year , p.Proof_Period , Count(*) As Number_Of_Proofs From (((WH_Proof p (NoLock) Left Join WH_Proof_List l (NoLock) On p.Company_Name = l.Company_Name And p.Tax_Agency_Id = l.Tax_Agency_Id And p.Region = l.Region And p.Tax_Class = l.Tax_Class And p.Sub_Region = l.Sub_Region) Left Join Work_Group w On l.Work_Group = w.Work_Group) Left Join Proof_Status s On p.Status = s.Status) Group By w.Work_Group_Desc , s.Status_Desc , p.Period_Type , p.Proof_Year , p.Proof_Period Union All Select 'Disb_Proof' , w.Work_Group_Desc , s.Status_Desc , p.Period_Type , p.Proof_Year , p.Proof_Period , Count(*) As Number_Of_Proofs From (((Disb_Proof p (NoLock) Left Join Disb_Proof_List l (NoLock) On p.Company_Name = l.Company_Name And p.Tax_Agency_Id = l.Tax_Agency_Id And p.Region = l.Region And p.Tax_Class = l.Tax_Class) Left Join Work_Group w On l.Work_Group = w.Work_Group) Left Join Proof_Status s On p.Status = s.Status) Group By w.Work_Group_Desc , s.Status_Desc , p.Period_Type , p.Proof_Year , p.Proof_Period Union All Select 'Company_Return' , w.Work_Group_Desc , s.Status_Desc , 'Q' As Period_Type , p.Proof_Year , p.Proof_Period , Count(*) As Number_Of_Proofs From (((Company_Return p (NoLock) Left Join Company_Return_List l (NoLock) On p.Company_Name = l.Company_Name And p.Tax_Agency_Id = l.Tax_Agency_Id And p.Return_Type = l.Return_Type) Left Join Work_Group w On l.Work_Group = w.Work_Group) Left Join Proof_Status s On p.Status = s.Status) Group By w.Work_Group_Desc , s.Status_Desc-- , p.Period_Type , p.Proof_Year , p.Proof_Period) As A
Brett8-)