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 |
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2008-10-29 : 05:24:47
|
| I am trying to create a procedure that returns a town beginning with a specified letter. The procedure would list all of the occurences with the specified letter and how many times occurs. This I can do fine. But I need to return the top 4 entries in terms of how many occurences only, if I add top 4 to this it just grabs the top 4 towns on the list :( I'm confused and don't get itsp_count_towns ( @theletter varchar(1)='')ASSELECT COUNT(tb_properties.prop_address3), prop_address3FROMtb_propertiesWHEREleft(TB_properties.prop_address3,1) = @theletterGROUP BY prop_address3 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-29 : 05:27:59
|
| [code]sp_count_towns (@theletter varchar(1)='')ASSELECT TOP 4 prop_address3,OccuranceFROM(SELECT COUNT(tb_properties.prop_address3) AS Occurance, prop_address3FROMtb_propertiesWHERETB_properties.prop_address3 like @theletter + '%'GROUP BY prop_address3)tORDER BY Occurance DESCGO[/code] |
 |
|
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2008-10-29 : 05:35:17
|
| wow, so quick at replying, I am forever in your debt, thank you |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-29 : 05:36:33
|
quote: Originally posted by godspeedba wow, so quick at replying, I am forever in your debt, thank you
welcome |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-29 : 05:40:47
|
[code]CREATE PROCEDURE sp_count_towns( @theLetter varchar(1) = '')ASSET NOCOUNT ONSELECT TOP 4 WITH TIES COUNT(*) AS Items, prop_address3FROM tb_propertiesWHERE prop_address3 LIKE @theLetter + '%'GROUP BY prop_address3ORDER BY COUNT(*) DESC[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|
|