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 |
|
DrewSQL
Starting Member
2 Posts |
Posted - 2011-09-02 : 10:29:54
|
| Hello,I may have many activity names that start with the letter A, none with B, some with C, etc. In my form I'm displaying a form button with each letter that starts the activity name, for example F for "Flying" will take you to a page with all activities that start with F. I want to display next to each letter a count of how many activities start with that letter. So my question is, how do I do a count in my query for this? This is my simplified table setup. If I can provide any additional info to help with this let me know. Thanks.activity_id int PK not nullactivity_name nvarchar null allowed |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-09-02 : 10:33:58
|
Something like this in your query:SELECT LEFT(activity_name,1),COUNT(*) FROM YourTable GROUP BY LEFT(activity_name,1) |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-09-02 : 10:34:15
|
SELECT LEFT(Activity_name,1) Letter, Count(*) ActivitiesFROM myTableGROUP BY LEFT(Activity_name,1) |
 |
|
|
DrewSQL
Starting Member
2 Posts |
Posted - 2011-09-02 : 10:58:37
|
| Thanks guys, this does the trick. |
 |
|
|
|
|
|