November 8, 2011 at 10:30 am
select distinct firstname,lastname,address,Null as address2,city,state,zipcode,country,phone,email,'ms' as datagroup
from marketscout02.dbo.users
where username <> 'CICintegration' and (cic_username is null or cic_username = '') and (email is not null and email <> '')
UNION
select distinct firstname,lastname,address,Null as address2,city,state,zipcode,country,phone,email,'cic' as datagroup
from marketscout02.dbo.users
where (username = 'CICintegration' or (cic_username is not null or cic_username <> '')) and (email is not null and email <> '')
With the union statement above...is there anyway to do a select count(*) on the unioned dataset?
I have a union statement similar to this but want to run some counts on columns in the combined/frankendata set.
Thanks in advance!
November 8, 2011 at 10:35 am
SELECT COUNT(*) FROM (
select distinct firstname,lastname,address,Null as address2,city,state,zipcode,country,phone,email,'ms' as datagroup
from marketscout02.dbo.users
where username <> 'CICintegration' and (cic_username is null or cic_username = '') and (email is not null and email <> '')
UNION
select distinct firstname,lastname,address,Null as address2,city,state,zipcode,country,phone,email,'cic' as datagroup
from marketscout02.dbo.users
where (username = 'CICintegration' or (cic_username is not null or cic_username <> '')) and (email is not null and email <> '')
) dtName
November 8, 2011 at 1:33 pm
Awesome...sometimes things in SQL are too simple to comprehend off the bat..lol
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply