Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2007, 10:18 AM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Count string occurences across recordset

Hello there,
I am trying to build a tag cloud from article keywords.
I have an "articles" table with a "keywords" column

id keywords
================
1 software, sql, microsoft
2 data, sql, software
3 music, software

What I need is to return something like this:

keyword occurences
========================
software 3
sql 2
microsoft 1
data 1
music 1

I guess I have to build a stored procedure with the following commands:
1. loop through the articles
2. split keywords string and add each keyword to a temporary table
3. select count occurrences and group by keyword

Can someone point me to the right direction to build this? I am using SQL Server 2005
Thanks in advance.

 
Old July 9th, 2007, 06:47 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

I don't know what the rest of the table looks like nor how you relate the "tags" to the Keywords column... but I would suggest that the table be properly normalized so that you don't need to go through all of that. A separate table with the ArticleID and 1 keyword per row in that separate table would be a healthy start.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Count unique occurences Umasriram2 Excel VBA 2 May 28th, 2008 05:10 AM
Count all occurences of a character in a string thomaz C# 2 February 9th, 2007 01:52 PM
Recordset Count starting from 1 till end nouky Classic ASP Databases 24 October 30th, 2006 06:22 PM
SQL record count / recordset chacquard Access VBA 4 July 3rd, 2004 04:41 AM
Recordset count niravp Classic ASP Databases 6 October 26th, 2003 02:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.