Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query problem

Status
Not open for further replies.

praween

MIS
May 26, 2003
3
TH
I have sql table

a b c
-----------------------------------
aa s 5
bb s 6
aa m 3
bb l 1

and want to show like this in data grid

aa s 5
m 3
bb s 6
l 1

How to query?
Thanks
 
This is a matter of displaying the data, not querying it. You say datagrid so I assume you mean .NET. Do the display formatting in your code, this is not a job for SQL
 
Have a look at the sql "GROUP BY" statement.

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Thanks for your comment . But my problem is when I query data with group by the left of column will display the same word every line ,i want to show it a top single line like header of each group .
aa. S. 5
-- m. 3
Bb. S. 6
-- m. 1
-- l. 3
Something like this,can sql query this final line.
Thanks again for your suggestion.
 
Then, as jbenson correctly mentioned, you are leaving the query grounds and entering parsing/display of the resultset.
Depending on whether this is for a desktop app or a web page, you would find the best help either in forum732, forum796 or in forum855.

Good luck!
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Do the query in Excel and use the Pivot Table feature. Eazy peazy.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
SkipVought pivot table in sql exist too...
this is query which produce output you are looking for
SQL:
declare @t as table
(
a varchar(10),
b varchar(10),
c varchar(10)
)
insert into @t
select 'aa','s','5'
insert into @t
select 'bb','s','6'
insert into @t
select 'aa','m','3'
insert into @t
select 'bb','l','1'



;with t as
(
	select ROW_NUMBER() over(partition by a order by b,c) r, a,b,c
from @t
)
select 
	a = case when r = 1 then a
				else '' end,
	b,
	c
from t

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top