Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2009-11-16 : 16:25:58
|
| I need to show a top 10 in this queries case for each store.So ID store 1 would have its top 10 records, store 2 its top 10 records and so on.Select CAST(Round((case when BaseHouseHoldCount = 0 then 0 else (ACCount/ BaseHouseHoldCount)end/ Case when TotalCustomercount = 0 then 0 else (TotalCustomerCount/TotalBlockSize)end)*100,0) as int) ACIndex, #ttMain.strMosaicCode, #ttMain.lngStoreID, strStoreName, CAST(Round((case when HVRCount = 0 then 0 else (HVRCount/ACCount)end /Case when TotalCustomerCount = 0 then 0 else(TotalCustomerCount/TotalBlockSize)end)*100,0) as INT)HVIndex, ACCount/TotalCustomerCount as 'Comp per', BaseHouseHoldCountFrom #ttMainLeft Join #ttTotal on #ttMain.lngStoreID = #ttTotal.TotalStoreIDLeft Join #ttGroupTotal on left(#ttMain.strMosaicCode,1) = #ttGroupTotal.designation and #ttMain.lngStoreID = #ttGroupTotal.GroupStoreIdInner Join (SELECT s.lngStoreId, CAST(si.txtStoreNotes as varchar(4)) + ' - ' + SUBSTRING(strStoreName, LEN(strStoreName) - 2, 3) + ' - ' + SUBSTRING(strStoreName, 0, LEN(strStoreName) - 2) as strStoreName FROM tblStore s JOIN tblStoreInfo si ON s.lngStoreId = si.lngStoreId WHERE s.blnIsActive = 1 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2009-11-16 : 16:29:29
|
| sorry by the ACIndex |
 |
|
|
JCirocco
Constraint Violating Yak Guru
392 Posts |
Posted - 2009-11-16 : 17:40:15
|
| Change to:Select Top 10CAST(Round...JohnIt's a small world (but I wouldn't want to paint it) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-17 : 01:52:26
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|