12,452,215 members (55,877 online)
Rate this:
See more:
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 .
Posted 19-Feb-13 19:08pm
ankur7891.5K
Updated 19-Feb-13 21:15pm
v2

Get summary from SQL, not from control.
—SA
AnkurGupta OM 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 20-Feb-13 2:32am

You need to tryout the query by yourself first.
Susheel Kumar Verma 20-Feb-13 2:05am

Do you want summary for row wise or column wise ?
AnkurGupta OM 20-Feb-13 3:17am

complete summary sir
if possible then coloumn wise

Rate this:

## 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!
v5
AnkurGupta OM 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 20-Feb-13 3:18am

check it it's working properly
Aarti Meswania 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 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 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 :)

Top Experts
Last 24hrsThis month
 Maciej Los 240 ppolymorphe 225 Richard MacCutchan 140 OriginalGriff 110 Dave Kreskowiak 90
 OriginalGriff 6,163 ppolymorphe 3,795 Karthik Bangalore 3,585 Maciej Los 3,180 Richard Deeming 2,835