Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

use column in Group By, but Hide column from the results set Expand / Collapse
Author
Message
Posted Wednesday, September 19, 2012 10:13 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 31, 2014 11:38 AM
Points: 32, Visits: 102
Is this possible in sql server 2008?
I want to use the column in the select, and group by. But want to hide the column from the results set?
Post #1361480
Posted Wednesday, September 19, 2012 10:18 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:39 PM
Points: 5,307, Visits: 12,334
preetid2 (9/19/2012)
Is this possible in sql server 2008?
I want to use the column in the select, and group by. But want to hide the column from the results set?


No. If you select a column, it will appear.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1361485
Posted Wednesday, September 19, 2012 10:20 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
Yes it is possible, but what it will give you?


SELECT Col1, Count_Rec
FROM (SELECT Col1, Col2, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2) aq




_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1361486
Posted Wednesday, September 19, 2012 10:24 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 7:16 AM
Points: 320, Visits: 1,094
Can you give an example of what you're thinking of?
Post #1361489
Posted Wednesday, September 19, 2012 10:30 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:39 PM
Points: 5,307, Visits: 12,334
Eugene Elutin (9/19/2012)
Yes it is possible, but what it will give you?


SELECT Col1, Count_Rec
FROM (SELECT Col1, Col2, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2) aq




Haha, what a fantastically useful query this would be



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1361494
Posted Wednesday, September 19, 2012 11:45 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
Phil Parkin (9/19/2012)
Eugene Elutin (9/19/2012)
Yes it is possible, but what it will give you?


SELECT Col1, Count_Rec
FROM (SELECT Col1, Col2, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2) aq




Haha, what a fantastically useful query this would be


Who knows, who knows...


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1361544
Posted Wednesday, September 19, 2012 12:51 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:44 PM
Points: 4,041, Visits: 9,188
You get too complicated. This should work.
This will also give incomplete information on how the groups are made.
SELECT Col1, Count(*) AS Count_Rec 
FROM MyTable
GROUP BY Col1, Col2




Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1361577
Posted Wednesday, September 19, 2012 1:38 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 31, 2014 11:38 AM
Points: 32, Visits: 102
Thanks Phil! this worked perfect!
Post #1361600
Posted Wednesday, September 19, 2012 1:45 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:39 PM
Points: 5,307, Visits: 12,334
preetid2 (9/19/2012)
Thanks Phil! this worked perfect!


I feel like I have entered a parallel universe.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1361602
Posted Wednesday, September 19, 2012 2:12 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
Phil Parkin (9/19/2012)
preetid2 (9/19/2012)
Thanks Phil! this worked perfect!


I feel like I have entered a parallel universe.


I knew that! Your avatar makes everything right! What a solution!



_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1361616
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse