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 2005 Forums
 Transact-SQL (2005)
 GROUPING PROBLEM

Author  Topic 

sateesh.sqldba
Starting Member

25 Posts

Posted - 2010-07-16 : 13:37:43
Hi Experts,

i have problem in grouping a single column like


Col1 Col2 Col3
1 img Data
2 Img1 Data1
3 Img2 Data2
4 Img1,img2 Data3
5 Img,img1,img2 Data4




when i used to group this using

col2,count(*) from table where condition group by col2

then result
Col2 Groupingvalue
img 1
Img1 1
Img2 1
Img1,img2 1
Img,img1,img2 1

but i need to display like this

Col1 Groupingvalue
img 2
Img1 3
Img2 3


please help me out


thanq inadvance


sateesh

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-16 : 14:14:17
you need to split the string to get each value in a separate column and then you can count and group.
Go to Top of Page

sateesh.sqldba
Starting Member

25 Posts

Posted - 2010-07-17 : 02:34:54
quote:
Originally posted by slimt_slimt

you need to split the string to get each value in a separate column and then you can count and group.


plz tel me how to split and count it

sateesh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-17 : 09:39:23
[code]
select stringval, count(*)
from table t
cross apply CSVTable(t.col2)
group by strval
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -