?
Solved

Grouping by Free Text Field

Posted on 2011-03-18
8
Medium Priority
?
398 Views
Last Modified: 2012-05-11
Hi All,

I am in a dilemma, I have this database I need to pull a count from but then this is to be based on a free text field. The data is recorded as follows:

Product Name
==================
Delegate 1 Email Address
Delegate 1 Name
Delegate 1 Job Title
Delegate 2 Email Address
Delegate 2 Name
Delegate 2 Job Title

So from the data above the count should be '2', I just need to be able to get the count when looping through the database to know how many delegates a customer has filled in.

Help...
0
Comment
Question by:pigmentarts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35165163
this sounds like some bad design, but anyhow:
can you clarify that the "count" will be based on the field's 2 first "words" aka everyting before the second space?
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 35165403
Sorry didn't make it clear, that is what is stored in 1 field i.e  'Delegate 1 Email Address'
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35165424
I understood that. so, please clarify if the rule is: "group by the first 2 words in the field value, aka everything before the second space in the string"
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35165440
anyhow, here some example:
declare @demo_table table  ( product_name varchar(100) )
insert into @demo_table values ( 'Delegate 1 Email Address')
insert into @demo_table values ( 'Delegate 1 Name')
insert into @demo_table values ( 'Delegate 1 Job Title')
insert into @demo_table values ( 'Delegate 2 Email Address')
insert into @demo_table values ( 'Delegate 2 Name')
insert into @demo_table values ( 'Delegate 2 Job Title')

select left( product_name, charindex(' ', product_name, charindex(' ', product_name) + 1 ))
     , count(*)
  from @demo_table
group by left( product_name, charindex(' ', product_name, charindex(' ', product_name) + 1 ))

Open in new window

0
 
LVL 12

Author Comment

by:pigmentarts
ID: 35165848
Yes angelIII I need to group by say the number of email addresses
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35166172
well, unless you clarify EXACTLY the rules to "count", I cannot give more concrete code than above.
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 35166276
I need to group by the number of times 'Email Address' appears in the list so I can get the count in this case which should be '2'. Sorry
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35166506
that is easy:
select count(*) from yourtable where product_name like '%Email Address%'

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question