I need some help understanding the order of how things will appear.I want 009 that's in the Reg field to be the last one to appear (200 should be in front of 009)DOC Region Area Dist Reg PHI <a href=region.aspx?Reg=C>PHI</a> PHI 01 <a href=areadistlisting.aspx?reg=C&Area=01>Area 1</a>C PHI 01 200 009PHI <a href=distdoclisting.aspx?dist=200>200</a>
This stored procedure produces the above table. I believe I don't have the order by set up correctly:order by doc, area, reg,regionacronym, dist (This is at the bottom of the stored procedure)SELECT '' AS doc, RegionAcronym, '' as area, '' as dist,'<a href=region.aspx?Reg=' + Reg + '>' + RegionAcronym + '</a>' as reg, SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'FROM T16Report where reg='c'group by RegionAcronym,regunionselect '' as doc,RegionAcronym, Area,'' as Dist,'<a href=areadistlisting.aspx?reg=' + reg + '&Area=' + Area + '>' +'Area ' + right(area,1) + '</a>' as reg, SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'from t16report where reg = 'c' and area='01'group by reg, RegionAcronym, areaunionselect RegionAcronym, '' as Area, '' as doc, '' as dist,'<a href=distdoclisting.aspx?dist=' + dist + '>' + dist + '</a>' as reg,SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'from t16report where dist='200'group by reg, RegionAcronym, area, distunionselect reg, RegionAcronym, area, Dist, DOC, SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'from t16report where doc='009' group by reg, RegionAcronym, area, Dist, DOC order by doc, area, reg,regionacronym, dist [code]I got it to work by forcing letters into the Dist fieldsand doing an order by dist but is there another way to do this? What get's counted first black spaces, letters then numbers? SELECT '' AS doc, RegionAcronym, '' as area, 'A' as dist,'<a href=region.aspx?Reg=' + Reg + '>' + RegionAcronym + '</a>' as reg, SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'FROM T16Report where reg='c'group by RegionAcronym,regunionselect '' as doc,RegionAcronym, Area, 'b' as Dist,'<a href=areadistlisting.aspx?reg=' + reg + '&Area=' + Area + '>' +'Area ' + right(area,1) + '</a>' as reg, SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'from t16report where reg = 'c' and area='01'--@areagroup by reg, RegionAcronym, areaunionselect RegionAcronym, '' as Area, '' as doc, 'd' as dist,'<a href=distdoclisting.aspx?dist=' + dist + '>' + dist + '</a>' as reg,SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'from t16report where dist='200'group by reg, RegionAcronym, area, distunionselect reg, RegionAcronym, area, 'e' as Dist , DOC, SUM(totpenfodds) AS 'totpenfodds', SUM(pendinfo1) AS 'pendinfo1', SUM(pendndds) AS 'pendndds', SUM(pendfo300) AS 'pendfo300', SUM(penddds300) AS 'penddds300', SUM(pend250) AS 'pend250', SUM(pend300) AS 'pend300', SUM(pend351) AS 'pend351', SUM(pend400) AS 'pend400'from t16report where doc='009'group by reg, RegionAcronym, area, Dist, DOC order by dist