Hi all,
I am having a few problems figuring how to get a result I need for a report in query analyser. I have a table called search_nearest_park and it has two colums in it called zip and created.
Zip stores post codes
Created stores the created date for record
I need to find the top 10 most searched for post codes from the table by grouping them but the problem is some begin with two characters and some with 1. The postcodes that start with only one have a numeric value as the second character so what I need my code to do is look at the first two characters unless the second one is numeric then only look at the first character.
I have got this far
-------------------------------------------
SELECT LEFT(Zip, 2) AS zip, COUNT(Zip) AS total
FROM Search_nearest_Park
WHERE (created BETWEEN '2006/06/01 00:00:00' AND '2006/06/30 00:00:00')
GROUP BY Zip
ORDER BY total DESC
-------------------------------------------
Being a total novice I am stuck now - any help will be greatly appreciated
Paul
I am having a few problems figuring how to get a result I need for a report in query analyser. I have a table called search_nearest_park and it has two colums in it called zip and created.
Zip stores post codes
Created stores the created date for record
I need to find the top 10 most searched for post codes from the table by grouping them but the problem is some begin with two characters and some with 1. The postcodes that start with only one have a numeric value as the second character so what I need my code to do is look at the first two characters unless the second one is numeric then only look at the first character.
I have got this far
-------------------------------------------
SELECT LEFT(Zip, 2) AS zip, COUNT(Zip) AS total
FROM Search_nearest_Park
WHERE (created BETWEEN '2006/06/01 00:00:00' AND '2006/06/30 00:00:00')
GROUP BY Zip
ORDER BY total DESC
-------------------------------------------
Being a total novice I am stuck now - any help will be greatly appreciated
Paul