Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Return sepcifc data on query Expand / Collapse
Author
Message
Posted Wednesday, June 26, 2013 9:37 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 2:36 PM
Points: 12, Visits: 40
If I run a query to return an email address from an emails replied to, I get some returnes with multiple email addresses with the email address I want at the end.

Example - Service, Customer Support, Customer123@provider.com

How do I remove the info I don't want in these rows but not affect the other rows that are correct?
Post #1467746
Posted Wednesday, June 26, 2013 9:41 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:05 PM
Points: 13,327, Visits: 12,820
bquintana (6/26/2013)
If I run a query to return an email address from an emails replied to, I get some returnes with multiple email addresses with the email address I want at the end.

Example - Service, Customer Support, Customer123@provider.com

How do I remove the info I don't want in these rows but not affect the other rows that are correct?


Hi and welcome to the forums. In order to help we will need a few things:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

Please take a few minutes and read the first article in my signature for best practices when posting questions.



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1467749
Posted Wednesday, June 26, 2013 10:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 2:36 PM
Points: 12, Visits: 40
Hopefully this helps understand what I am asking.

SELECT [t].[TicketID] as "Ticket"
,[th].[TicketHistoryID]
,[ac].[STR_ACCOUNT_NUMBER]
,[om].[body]
,[t].[TicketBoxID]
,[tb].[Name] as "Ticket Group"
,[g].[GroupName]
,[t].[Subject]
,[t].[Contacts]
,[t].[DateCreated]
FROM [Emails].[dbo].[Tickets] [t]
left outer join
[Emails].[dbo].[TicketBoxes] [tb] on [t].[TicketBoxID] = [tb].[TicketBoxID]
left outer join
[SYS_Live].[dbo].[ACCOUNT] [ac]
on [t].[Contacts] collate SQL_Latin1_General_CP1_CI_AS
= [ac].[STR_EMAIL_ADDRESS] collate SQL_Latin1_General_CP1_CI_AS

left outer join
[SYS_Live].[dbo].[vwAPPS_SUMMARY] [vwapp]
on [t].[Contacts] collate SQL_Latin1_General_CP1_CI_AS
= [vwapp].[STR_EMAIL_ADDRESS] collate SQL_Latin1_General_CP1_CI_AS

Where
[t].[datecreated] between '05-29-2013' and '05-30-2013'
and [th].[TicketBoxID]in ('154','155','156','158','160','165')
and [om].[body] not like '%auto-%'
Order by [t].[DateCreated] desc



  Post Attachments 
SQL_Example.xlsx (4 views, 10.17 KB)
Post #1467757
Posted Wednesday, June 26, 2013 10:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:05 PM
Points: 13,327, Visits: 12,820
What would really help is:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

You are asking for help writing code against some sql tables but I don't have those tables to work with. From the excel spreadsheet I am guessing that the best way to accomplish is with a CLR proc. You will need to parse the values on commas first and then look for valid emails using a regex. I can help you figure this out but with no tables it is guess work on my part.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1467766
Posted Wednesday, June 26, 2013 10:38 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:11 PM
Points: 31,368, Visits: 15,837
What Sean said. This might help: http://www.sqlservercentral.com/articles/66909/

However with regards to #3, explain how the results are calculated. In your example, I assume you want "Customer123@provider.com", but you never say that. Or do you want another value?

What if there are multiple values in there? Or if this value is at the beginning? Do you only want the last email?

To try and help you code this, we need some better understanding of the rules under which you are operating.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1467772
Posted Wednesday, June 26, 2013 10:48 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 7:08 PM
Points: 4,046, Visits: 9,205
Sean Lange (6/26/2013)
What would really help is:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

You are asking for help writing code against some sql tables but I don't have those tables to work with. From the excel spreadsheet I am guessing that the best way to accomplish is with a CLR proc. You will need to parse the values on commas first and then look for valid emails using a regex. I can help you figure this out but with no tables it is guess work on my part.


Wouldn't the 8K Splitter function work along with one or two CHARINDEX?
I'm not sure if it will get too complex depending on the OP requirements.



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1467778
Posted Wednesday, June 26, 2013 11:49 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:05 PM
Points: 13,327, Visits: 12,820
Luis Cazares (6/26/2013)
Sean Lange (6/26/2013)
What would really help is:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

You are asking for help writing code against some sql tables but I don't have those tables to work with. From the excel spreadsheet I am guessing that the best way to accomplish is with a CLR proc. You will need to parse the values on commas first and then look for valid emails using a regex. I can help you figure this out but with no tables it is guess work on my part.


Wouldn't the 8K Splitter function work along with one or two CHARINDEX?
I'm not sure if it will get too complex depending on the OP requirements.


I was thinking that we could use the 8k splitter in a CLR sproc and then use a .net regex to only get those that also have a valid email. This got me to thinking that I need to create my own CLR for validating emails though...thanks!!!


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1467802
Posted Wednesday, June 26, 2013 3:00 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 2:36 PM
Points: 12, Visits: 40

This is a learning experience on this one. Self taught and learning as I go.

I'd like result to be the email address only and it is the last entry in the line seperated by commas, but only if there are other internal email address. Otherwise it is just the reply to email address.

so the field result looks like any one of these examples.

Customer Support, Customer45@hotmail.com
s_prod_i3admin, s_prod_i3admin, Customer12@yahoo.com
1234Customer@msn.com

Thank you for your patience.





Post #1467882
Posted Wednesday, June 26, 2013 3:05 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:11 PM
Points: 31,368, Visits: 15,837
You'll have to provide mode DDL and sample data. Also, how do you define an internal address?






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1467883
Posted Thursday, June 27, 2013 8:49 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:05 PM
Points: 13,327, Visits: 12,820
See if something like this will get you started. Please notice how I posted ddl and sample data in a consumable format.

if OBJECT_ID('tempdb..#Something') is not null
drop table #Something

create table #Something
(
Ticket int,
contacts varchar(100)
)

insert #Something
select 4368642, 'Customer Support, Customer45@hotmail.com' union all
select 4368640, 's_prod_i3admin, s_prod_i3admin, Customer12@yahoo.com' union all
select 4368023, '1234Customer@msn.com'

select *
from #Something s
cross apply dbo.DelimitedSplit8K(s.contacts, ',') x
where CHARINDEX('@', x.Item) > 0

You can find the code for the DelimitedSplit8K function by following the link in my signature about splitting strings.



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1468204
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse