Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

Friday, March 30, 2012

If I could explain the problem..........

In SQL database we need to concatenate 2 fields to display in one and turn them into an email address in the following format

joe.bloggs@.company.co.uk

They are the following: forename & surname

The expression will require a . to be added between the forename & surname and @.company.co.uk at the end.

Anyone help...... ?This should work:

SELECT forename || '.' || surname || '@.company.co.uk' AS [name]
FROM [table]
[WHERE ...];

Wednesday, March 28, 2012

IF EXISTS SQL Question - using Query Analyzer

I want to only go after Distinct email addressess that contain an @. symbol.

But then I want to return all fields. How do you correctly do that for Microsoft SQL Server?

IFEXISTS (SELECT DISTINCT user_usernameFROM usrWHERE(user_usernameLIKE N'%@.%'))SELECT *FROM usrOrder By user_username

Try something like:

IFEXISTS (SELECT DISTINCT user_usernameFROM usrWHERE(user_usernameLIKE N'%@.%'))
BEGIN

SELECT *
FROM usrOrder By user_username
END 
|||

IF EXISTS only checks for existence of a record matching the WHERE condition. The SELECT is never evaluated. So DISTINCT in SELECT doesnt help. you might as well use SELECT * or SELECT 1. As soon as it finds at least one record that has an "@." in the User_Username the condition evaluates to TRUE.