Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
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?
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?
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2013-06-21 : 15:57:38
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.
Rasta Pickles
Posting Yak Master
174 Posts
Posted - 2013-06-22 : 02:19:57
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.