Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: GROUP BY a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 11185 of 11431
Post > Topic >>

Re: GROUP BY a computed column

by "Plamen Ratchev" <Plamen@[EMAIL PROTECTED] > Jun 26, 2008 at 04:54 PM

You can do this in a single query grouping by the expression extracting the

first word from the string:

CREATE TABLE Foo (
 keycol INT PRIMARY KEY,
 datacol VARCHAR(35));

INSERT INTO Foo VALUES(1, 'one way');
INSERT INTO Foo VALUES(2, 'one day');
INSERT INTO Foo VALUES(3, 'next day');

SELECT LEFT(datacol, CHARINDEX(' ', datacol) - 1) AS first_word,
          COUNT(*) AS cnt
FROM Foo
GROUP BY LEFT(datacol, CHARINDEX(' ', datacol) - 1);


HTH,

Plamen Ratchev
http://www.SQLStudio.com
 




 4 Posts in Topic:
GROUP BY a computed column
The Quiet Center <theq  2008-06-26 13:12:49 
Re: GROUP BY a computed column
"Plamen Ratchev"  2008-06-26 16:54:56 
Re: GROUP BY a computed column
--CELKO-- <jcelko212@[  2008-06-26 14:30:36 
Re: GROUP BY a computed column
Alex Kuznetsov <alkuzo  2008-07-02 09:47:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 13:55:33 CDT 2008.