Groups | Blog | Home
all groups > sql server programming > march 2007 >

sql server programming : Counting Items in Tables when part string and multivalue


stumpy_uk via SQLMonster.com
3/1/2007 10:52:45 PM
Firstly thank you all for a wonderful site every day I find answers to
problems by searching these pages it really is fantastic.

My Problem which I have not been able to find an answer for.

I have two tables as setup below.

Table 1
++++++++++++++++++++++++
ID unique
Type Int
Text varchar(50)

Table 2
++++++++++++++++++++++++
.....loads of other fields
Types varchar(500)
scoring varchar(50)

An example of the Data

Table1
+++++++++++++++++++++++++
1,3,Apple
2,3,Bananna
3,3,Pear
4,3,Grape
5,3,Peach

Table 2 (has a number of these in the one column separated by , (came from a
Web Page multi - select..not my doing)
+++++++++++++++++++++++++
......."apple,bananna","Gold"
......."apple, pear", "Silver"
......."pear, grape, apple", "Gold"
......."grape, bananna", "Bronze"

and I want to create a report that shows each entitiy from Table 1 and a
total of Gold Silver Bronze, e.g.

Type Gold Silver Bronze
=============================
Apple 2 1 0
Bananna 1 0 1
Pear 1 1 0
Grape 1 0 1
Peach 0 0 0

I can do it in ASP via an Instr command and allocating a counter etc, but
wondered if it was possible with an SQL script.

Thanks for any help you can give me...

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200703/1
stumpy_uk via SQLMonster.com
3/1/2007 10:54:05 PM
Sorry Ignore this I put it in the wrong section...

--
Message posted via http://www.sqlmonster.com
AddThis Social Bookmark Button