Solved

Grouping by Free Text Field

Posted on 2011-03-18
8
393 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
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 500 total points
ID: 35166506
that is easy:
select count(*) from yourtable where product_name like '%Email Address%'

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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