Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Return sepcifc data on query


Return sepcifc data on query

Author
Message
bquintana
bquintana
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
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?
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16675 Visits: 17035
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)
bquintana
bquintana
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
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
Attachments
SQL_Example.xlsx (4 views, 10.00 KB)
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16675 Visits: 17035
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)
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36365 Visits: 18759
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
My Blog: www.voiceofthedba.com
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8589 Visits: 18170
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.
General Disclaimer:
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?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16675 Visits: 17035
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!!! :-D

_______________________________________________________________

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)
bquintana
bquintana
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
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.
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36365 Visits: 18759
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
My Blog: www.voiceofthedba.com
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16675 Visits: 17035
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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search