What about a CASE statement to insert a constant into the name fields if
they are blank? Then, you can use a distinct to ensure you return only one
email address for null names?

SOmething like:

Select DISTINCT
CASE WHEN FirstName is null THEN 1 ELSE table.firstName END AS FirstName,
CASE WHEN LastName is null THEN 2 ELSE table.LastName END AS LastName,
emailAddress

Every record with a null first and last name should look the same, unless
their email addy is different. Think that'll work.

Syntax untested of course.

HTH,
G

On 10/30/06, Duane <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I have a sql question for anyone willing to help me get my head unstuck.
>
>
> I have the following sample data:
>
> RegDate FirstName       LastName        Email
> 10/1/2006       NULL            NULL            [EMAIL PROTECTED]
> 10/2/2006       NULL            NULL            [EMAIL PROTECTED]
> 10/2/2006       NULL            NULL            [EMAIL PROTECTED]
> 10/3/2006       Fred            Flintstone      [EMAIL PROTECTED]
> 10/8/2006       Barney  Rubble  [EMAIL PROTECTED]
> 10/9/2006       NULL            NULL            [EMAIL PROTECTED]
>
> In my returned dataset I need to get the following:
> 10/1/2006       NULL            NULL            [EMAIL PROTECTED]
> 10/2/2006       Fred            Flintstone      [EMAIL PROTECTED]
> 10/8/2006       Barney  Rubble  [EMAIL PROTECTED]
>
> Basically I need all records that have a first and last name, and only the
> null records that have a distinct email address.
>
> I had written the following:
>
> select  RegDate, Firstname, Lastname, Email
> from            dbo.LitRequest
> where           (FirstName is not null or FirstName <> '')
>                 or l.Email not in (
>                         select Email from dbo.LitRequest
>                         where FirstName is not null or FirstName <> '')
>
> The only thing I can think of is to use a cursor and generate a temp table
> on the fly. Cursors tend to be processor hogs and I'm looking for an
> alternative.
>
> Thanks,
> Duane
>
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:218733
Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5

Reply via email to