HelloI have created a store procedure to display a report and it works fine. But there is a small problems, which I don't know how to solve it. here is a problem,The store procedure that I wrote which displays the result like below:SocialSecurityNumber ClearedDate Type DDS TotalCleared 2 111223333 1/1/2009 DE BO 1 444552896 1/5/2009 SM CT 1Number "2" is sum of 1 + 1, it supposes to display at bottom of column "TotalCleared" (not on top).DOES ANYONE HERE KNOW HOW TO REVERSE IT TO BOTTOM????THANKS IN ADVANCEBELOW IS MY STORE PROCEDUREALTER PROCEDURE [dbo].[WklyCasesClearedWithNoReturns] -- Add the parameters for the stored procedure here @Start Datetime, @End Datetime, @Office varchar(5)ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; --select * from ROCAPcreate table #temp(SocialSecurityNumber varchar(9),ClearedDate datetime,[Type] varchar(5),DDS varchar(50),TotalCleared int )if @office = 'ALL'begin--DEinsert into #tempselect SocialSecurityNumber, DEClearedDate as ClearedDate, 'DE' as [Type], DDS, NULL from ROCAPData whereDEClearedDate between @start and @Endand DESecondClearedDate is NULLand DEThirdClearedDate is NULLand DEFourthClearedDate is NULLOrder BY ISNULL( DEClearedDate, '31-Dec-2090')--Somaticinsert into #tempselect SocialSecurityNumber, SomaticMCClearedDate as ClearedDate, 'SM' as [Type], DDS, NULL from ROCAPData where SomaticMCClearedDate between @start and @Endand SomaticMCSecondClearedDate is NULLand SomaticMCThirdClearedDate is NULLand SomaticMCFourthClearedDate is NULLOrder BY ISNULL( SomaticMCClearedDate, '31-Dec-2090')--Psycinsert into #tempselect SocialSecurityNumber, PsycMCClearedDate as ClearedDate, 'PM' as [Type], DDS, NULL from ROCAPData where PsycMCClearedDate between @Start and @Endand PsycMCSecondClearedDate is NULLand PsycMCThirdClearedDate is NULLand PsycMCFourthClearedDate is NULLOrder BY ISNULL( PsycMCClearedDate, '31-Dec-2090')endelsebegin--DEinsert into #tempselect SocialSecurityNumber, DEClearedDate as ClearedDate, 'DE' as [Type], DDS, NULL from ROCAPData whereDEClearedDate between @Start and @Endand DESecondClearedDate is NULLand DEThirdClearedDate is NULLand DEFourthClearedDate is NULLand DDS = @officeOrder BY ISNULL( DEClearedDate, '31-Dec-2090')--Somaticinsert into #tempselect SocialSecurityNumber, SomaticMCClearedDate as ClearedDate, 'SM' as [Type], DDS, NULL from ROCAPData where SomaticMCClearedDate between @Start and @Endand SomaticMCSecondClearedDate is NULLand SomaticMCThirdClearedDate is NULLand SomaticMCFourthClearedDate is NULLand DDS = @officeOrder BY ISNULL( SomaticMCClearedDate, '31-Dec-2090')--Psycinsert into #tempselect SocialSecurityNumber, PsycMCClearedDate as ClearedDate, 'PM' as [Type], DDS, NULL from ROCAPData where PsycMCClearedDate between @Start and @Endand PsycMCSecondClearedDate is NULLand PsycMCThirdClearedDate is NULLand PsycMCFourthClearedDate is NULLand DDS = @officeOrder BY ISNULL( PsycMCClearedDate, '31-Dec-2090')endSelect SocialSecurityNumber, ClearedDate, [Type], DDS, Count(*) As TotalClearedfrom #tempGroup By SocialSecurityNumber, ClearedDate, [Type], DDSUnionSelect Null, Null, Null, Null, count(*)as TotalCleared from #tempEND
Joseph