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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select statement

Author  Topic 

joelseverich
Starting Member

34 Posts

Posted - 2009-02-12 : 17:27:24
Hi
is there a way to use a StarsWith when u use the group by statement
ex

TB1
code name
1 one
11 two
111 three
112 four
2 five
21 six
211 seven

I want to group all records that star with '2' and '1'

please help me

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-12 : 17:35:05
Yes,

Select Left(code,1)as code,Count(Name) NameCount
from Table
Group by Left(code,1)
Order by code
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-12 : 20:46:11
[code]Select substring(code,1,1)as code,Count(*) Cnt,MAX(Name),MIN(Name),...
from Table
Group by substring(code,1,1)
Order by code
[/code]
Go to Top of Page
   

- Advertisement -