Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I am using vb.net with visual studio 2005 and sqlserver 2000
I have a grid view named as gb1
WHICH HAS FOUR COLOUMNS A,B,C,D
and has the value like
 
A        B       C       D
1.0	2.0		1.0
2.0	1.0		3.0
-		2.0	
 
I WANT TO FIND A SUMMARY
 
LIKE
 
1.0 OCCURS =3 TIMES
2.0 OCCURS =3 TIMES
3.0 OCCURS =1 TIMES
 

i don't find the logic of this summary .
Please Help me regarding this condition.
Posted 19-Feb-13 20:08pm
ankur7891.4K
Edited 19-Feb-13 22:15pm
v2
Comments
Sergey Alexandrovich Kryukov at 20-Feb-13 1:09am
   
Get summary from SQL, not from control.
—SA
AnkurGupta OM at 20-Feb-13 1:11am
   
sir then what query can i use .
i am using count with select but not find such a result i wanr
Sandeep Mewara at 20-Feb-13 2:32am
   
You need to tryout the query by yourself first.
Susheel Kumar Verma at 20-Feb-13 2:05am
   
Do you want summary for row wise or column wise ?
AnkurGupta OM at 20-Feb-13 3:17am
   
complete summary sir
if possible then coloumn wise

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

this way...
select val,count(*) as Occurance from
(
    select a as Val from tblnm   _
    union all                     |
    select b from tblnm           |
    union all                      > this will get col a,b,c,d & then using union all merge all cols
    select c from tblnm           |
    union all                     |
    select d from tblnm          _|
) as t
group by val --here it grouped by val 
Happy Coding!
Smile | :)
  Permalink  
v5
Comments
AnkurGupta OM at 20-Feb-13 3:14am
   
mam here is a problem that i m not doing the selection on the basis of first coloumn let us consider the condition
a b c d
1.0 1.0
now the answer comes as 1.0 occurs 2 times but the query will not give right answer
Aarti Meswania at 20-Feb-13 3:18am
   
check it it's working properly
Aarti Meswania at 20-Feb-13 3:19am
   
see this example
with a as
(
select 10 as a, 10 as b, 1 as c union all
select 2 as a, 10 as b, 3 as c union all
select 1 as a, 3 as b, 2 as c
)
select count(*),a from
(
select a from a
union all
select b from a
union all
select c from a
) as t
group by a
AnkurGupta OM at 20-Feb-13 3:26am
   
thanks ma'am ,
But mam one problem is also here.
tell me how this query works means how this query fetch the values
Aarti Meswania at 20-Feb-13 3:39am
   
see solution
I have describe there
see set of 4 select Queries with union all copy that and execute you will see all 4 column values are gather now in a single column 'val'
 
and then I have grouped that val column and count how many time particular val occur
 
Hope you understand how it worked :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 436
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 170
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100