I have a column titled email. Obviously this is a list of emails. where someone has 2 emails in their record, the database separates them by ' ' (space).
I need to deleted everything from the space (including the space)
I've tried
UPDATE employee SET email = TRIM(TRAILING ' ' FROM email);
which I found in heaps of other posts but it does nothing!
Thanks!
You can use:
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_substring-index
it should be something like:
update employee set email = substring_index(email, ' ', 1)
Related
I am trying to extract words from a column in a table only if the entire word is in uppercase letters (I am trying to find all acronyms in a column). I tried using the following code, but it gives me all capital letters in a string even if it is just the first letter of a word. Appreciate any help you can provide.
SELECT title, REGEXP_REPLACE(title, '[^A-Z]+', '', 'g') AS acronym
FROM table;
Here is my desired output:
title
acronym
I will leave ASAP
ASAP
David James is LOL
LOL
BTW I went home
BTW
Please RSVP today
RSVP
You could use this regular expression:
regexp_replace(title, '.*?\m([[:upper:]]+)\M.*', '\1 ', 'g')
.*? matches arbitrary letters is a non-greedy fashion
\m matches the beginning of a word
( is the beginning of the part we are interested in
[[:upper:]]* are arbitrarily many uppercase characters
) is the end of that part we are interested in
\M matches the end of a word
.* matches arbitrary characters
\1 references the part delimited by the parentheses
You could try REGEXP_MATCHES function
WITH data AS
(SELECT 'I will leave ASAP' AS title
UNION ALL SELECT 'David James is LOL' AS title
UNION ALL SELECT 'BTW I went home' AS title
UNION ALL SELECT 'Please RSVP today' AS title)
SELECT title, REGEXP_MATCHES(title, '[A-Z][A-Z]+', 'g') AS acronym
FROM data;
See demo here
I have a data set (work.employees) where each field is an element of an email to be sent out. Example record: Smith, John, John.Smith#Company.com, JohnsManager#Company.com. For each record, I need to send a separate email based on the information there. I can send one email with macro variables, and have piddled around with a data null email, but the iteration isn't happening. Suggestions would be very appreciated. Thanks.
So you want to send email notification through sas? The issue is two folded. First you need to make sure your SMTP server is properly configured in SAS. Secondly you have to make the required mailing software.
For first bit follow the guide in http://support.sas.com/kb/19/767.html
Now what you want (apparently) is to parse/select the emails. I'm going to assume you only select them from data set.
Proc sql;
select distinct(emails) into: resplist separated by ' ' from mail_set where emails like '%#%';
/*Here I'm selecting only those that have # mark in the cells.
You can add parser as you need. (question is a bit oddly worded.*/
quit;
Alternatively, you can hardCode the addresses. (I suggest you try 1st with this so you know your sending code works.
%let respList="Frist.last#email.com" "Second.Recipiant#email.com";
FILENAME Mailbox EMAIL &respList.
Subject="Email delivery for you";
DATA _NULL_;
FILE Mailbox;
PUT "Good day,";
put ;
PUT "Remain calm. This is a test.";
PUT ;
run;
You can also add sas datasets informatin, but bear in mind that spamming stuff through email is usually bad idea.
If you want to send one email per record, it's better to use the !EM_ directives in your datastep.
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002058232.htm
filename reports email "Jim.Smith#work.com";
data _null_;
file reports;
length name dept $ 21;
input name dept;
put '!EM_TO! ' name;
put '!EM_SUBJECT! Report for ' dept;
put name ',';
put 'Here is the latest report for ' dept '.' ;
if dept='marketing' then
put '!EM_ATTACH! c:\mktrept.txt';
else /* ATTACH the appropriate report */
put '!EM_ATTACH! c:\devrept.txt';
put '!EM_SEND!';
put '!EM_NEWMSG!';
put '!EM_ABORT!';
datalines;
Susan marketing
Peter marketing
Alma development
Andre development
;
run;
How can I setup conditional formatting using ExactTarget personalization? I want to only show the punctuation if the first name exists.
For example, if name exists subject is NAME! Rest of Subject. but if the name field is blank then Rest of Subject.
%% first_name %%! Rest of Subject. ends up returning ! Rest of Subject. if my first_name value is blank.
%%[
If Not Empty([first_name]) Or [first_name] != "" Then
Set #salutation = Concat(ProperCase([first_name]),'! ')
Else
Set #salutation = ""
EndIf
]%%
%%=v(#salutation)=%%Rest of Subject.
Notes:
This assumes that the column with first name is "first_name";
This assumes that the first_name column could come in as NULL or empty;
The space that will appear after the exclamation point is in the variable;
Place this in the email, and in the subject line input field, insert: %%=v(#salutation)=%%Rest of Subject.
I have a query:
SELECT phone,
to_char(appt_date,'MM/DD/YYYY'),
time_text,
staff_email || subject_line as title,
staff_wav,
agency_wav
FROM phone_dialer
that is sent to a csv file
That results in
9105554444,07/01/2011,08:30am,me#myemail.orgGADK082493,staffid0827,Coastal Counseling
or
9105554444,07/01/2011,08:30am,me#myemail.orgGADK082493,staffid0827,Smith, Bob
The "agency_wav" column could have a name of company. I have tried several ways to remove the comma between Smith, Bob and am failing miserably.
Can anyone steer me to a resolution?
Answer to title, since the body of the question is unclear.
Fastest way to remove commas from a string:
SELECT translate('Smith, Bob, foo,,,bar', ',', '');
Related answer addressing translate() / replace():
Looking for phone number containing a minus, like "123-456789"
If your surround your query with the syntax COPY () TO STDOUT WITH CSV; then it will construct the CSV output and automatically quote the field values that contain commas.
If you want to manually do it in the query, try replace(agency_wav,',','').
The preferred way to create CSV is to use COPY command.
If by some reason you don't want or can't use it, you just need make value returned in the column CSV friendly that is enclose value in double quotes and escape existing double quotes by duplicating them in the string. This will preserve correct value (that is all commas) but will not break CSV format.
SELECT phone,
to_char(appt_date,'MM/DD/YYYY'),
time_text,
staff_email || subject_line as title,
staff_wav,
'"' || replace(agency_wav, '"', '""') || '"'
FROM phone_dialer
This will produce the following line
9105554444,07/01/2011,08:30am,me#myemail.orgGADK082493,staffid0827,"Smith, Bob"
Note quoted value which has comma.
I have two strings in SQL and the REPLACE function only works on one of them, why is that?
Example 1:
SELECT REPLACE('18 286.74', ' ', '')
Example 2:
SELECT REPLACE('z z', ' ', '')
Example 1's output is still "18 286.74" whereas Example 2's output is "zz". Why does SQL not react the same way to both strings?
UPDATE:
When running select replace('123 123.12', ' ', '') that works fine, still not with '18 286.74'.
Test it the following way.
select unicode(substring('18 286.74', 3, 1))
If the code returns 32 then it's a space, if not, it's a different Unicode character and your replace ' ' won't work.
maybe cast is needed.
UPD: or not(on sql 2005 works fine too)
Are you sure it is a space? i.e. the same whitespace character that you are passing as the second argument? The code you've posted works fine for me on SQL Server 2008.
Re working on your friends PC - perhaps the whitespace got normalized when you sent it to him?
You are probably using non-breakable space.
I could reproduce it by typing ALT+0160 into the number in SELECT REPLACE('18 286.74', ' ', '')
Could you please issue this following:
SELECT CAST('18 286.74' AS BINARY), REPLACE('18 286.74', ' ', '')
by copying the '18 286.74' from REPLACE into CAST?
I was having the same issue and found that it was a char(10) (line feed). when copied out of Managment Studio it became a char(32) but in the record it was a char(10) try
Select Replace(#string, char(13), '')