SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inserting a '.' when encountering a capital letter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rasta Pickles
Posting Yak Master

United Kingdom
171 Posts

Posted - 06/21/2013 :  13:50:28  Show Profile  Reply with Quote
Two questions in one.

CREATE TABLE #test (userx NVARCHAR(MAX))

INSERT INTO #test VALUES ('NoodlesNoggin@emailaddress.here')
INSERT INTO #test VALUES ('MoodlesNoggin@emailaddress.here')
INSERT INTO #test VALUES ('SoodlesNoggin@emailaddress.here')
INSERT INTO #test VALUES ('ToodlesNoggin@emailaddress.here')
					
DECLARE @a NVARCHAR(MAX)


1) How do I get a '.' in the email address? The criteria in English would be "check the string, ignore the first character, find the first occurence of a capital letter and insert a period before it".

2) Having done so, how would I get these records into @a so that I can use SQL Mail to generate an email to them?

Without doing 1), I only seem to be able to get the last value into @a?

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 06/21/2013 :  14:19:15  Show Profile  Reply with Quote
Here is one way:
SELECT STUFF('ToodlesNoggin@emailaddress.here', PATINDEX('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]%', STUFF('ToodlesNoggin@emailaddress.here' COLLATE Latin1_General_CS_AS, 1, 1, '') ) + 1, 0, '.')
Go to Top of Page

Rasta Pickles
Posting Yak Master

United Kingdom
171 Posts

Posted - 06/21/2013 :  15:46:47  Show Profile  Reply with Quote
Outstanding.

Now, courtesy of your code, those four email addresses are correctly formatted; how do I get them into a variable so that I can email them via SQL Mail?
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3704 Posts

Posted - 06/21/2013 :  15:57:38  Show Profile  Reply with Quote
Do you mean like a comma or semi-colon separated list of e-mail addresses?
SET @a = (SELECT userx+';' FROM #test FOR XML PATH(''))
Of course you will need to use Lamprey's stuffing instead of userx in the above to get the period between the first and last names.
Go to Top of Page

Rasta Pickles
Posting Yak Master

United Kingdom
171 Posts

Posted - 06/22/2013 :  02:19:57  Show Profile  Reply with Quote
Thanks both, your solutions worked a treat!

(Why do other forums that I've googled insist there was no way to do what I wanted unless I used complicated functions?)

You guys really are SQL wizards.


Edited by - Rasta Pickles on 06/22/2013 06:39:15
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000