Help with a Query

  • Thread starter Thread starter Nom D. Plume
  • Start date Start date
N

Nom D. Plume

I'm a novice to SQL queries, so I'm using MS Excel to get the results I
need.
Now, I'm stuck and need some help.

I have a field that is populated with an email address, or else it is null.
I need to create another field that shows either "Y" or "N" to indicate the
presence of the email address in the original field.

Any help greatly appreciated.
 
Hi
You could use a straight IF function for this. It depends on what you are
checking for as to how to use it, though. Do you need to check for the cell
not being blank, to contain an @, or what?
One example is:
=IF(ISERROR(FIND("@",C6)),"N","Y")

Hope this helps.
Andy.
 
Nom D. Plume said:
I'm a novice to SQL queries, so I'm using MS Excel to get the results I
need.
Now, I'm stuck and need some help.

I have a field that is populated with an email address, or else it is null.
I need to create another field that shows either "Y" or "N" to indicate the
presence of the email address in the original field.

It depends on the SQL your target data source supports. For an SQL Server
database you could do something like this:

SELECT mytable.email, CASE LTRIM(RTRIM(ISNULL(mytable.email, ''))) WHEN
'' THEN 'N' ELSE 'Y' END AS isEmail
FROM mydatabase.mytable mytable

In the example above, if the email column is null it is replaced with a
blank string (the ISNULL function). Then leading and trailing spaces are
stripped off (LTRIM and RTRIM) in case the column is filled with spaces. The
final result is tested against an empty string (''). If the test is true the
CASE statement will return 'N'. Otherwise if there is ANYTHING in the column
it will return 'Y'.

Going against an ODBC database will result in a different SELECT statement.
 
Back
Top