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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Suppressing Column Data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-21 : 11:00:47
Target writes "Sorry, this is probably too easy a question or has already been asked & answered, but I searched and can't find it. A couple of SQL programmers here swear that there is a method to suppress duplicate column data using a simple TSQL SELECT statement. I have a hypothetical table (tblUsers) with 2 columns (GroupID, UserName) and I want my output to look like this:

GroupID UserName GroupID UserName
------- -------- ------- --------
100 Alan 100 Alan
Bob instead of 100 Bob
Craig 100 Craig
200 Daniel 200 Daniel
Mike 200 Mike

A standard SELECT GroupID,UserName FROM tblUsers GROUP BY GroupID will display GroupID on each row of the output. I can do this with cursors by converting the GroupID to spaces when it changes but I'm looking for a way using the SELECT statement parameters.

Are my coworkers full of beans?"

skchaman
Starting Member

6 Posts

Posted - 2004-10-16 : 04:23:37
Hi I used the following in my query

select
id = case when name = (select min(name) from t t2 where t.id = t2.id) then id else null end ,
name, Qty
from t
order by id, name

and its working fine and giving me an output as follows

GroupID UserName Qty
------- -------- -------
100 Alan 100
Bob 100
Craig 100
200 Daniel 200
Mike 300

Now I want My Out put as follows:

GroupID UserName Qty
------- -------- -------
100 Alan 100
Bob 100
Craig 100

Subtotal 300

200 Daniel 200
Mike 300

Subtotal 500

Grand Total 800

Can Anybody Help
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-10-16 : 05:05:08
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41363
Go to Top of Page
   

- Advertisement -