mcsolas
asked on
Need to combine 2 queries
I have 2 queries that I need to merge into 1 statement. I am trying to create a list of those who have successfully logged in to the system in the last (14) days.
The first query returns only the Users.LoginSuccess column. The second returns the other information I need to bind to that so that the query outputs all of the following rows:
Users.LoginSuccess + ProviderGroup.Company, ProviderGroup.NameFirst, ProviderGroup.NameLast, ProviderGroup.GroupSize, ProviderGroup.City, ProviderGroup.State,
ProviderGroup.ReferrerName , ProviderGroup.SignOnDate, ProviderGroup.Status
1. The following query works to pull LoginSuccess values:
SELECT Users.LoginSuccess
FROM Users
WHERE Users.UserTable='Provider'
AND Users.UserTableID
IN
(SELECT Provider.ProviderID
FROM Provider
WHERE Provider.ProviderGroupID
IN (SELECT ProviderGroup.ProviderGrou pID
FROM ProviderGroup
WHERE (ProviderGroup.SignOnDate > Getdate() - 14)
AND ProviderGroup.Status = 1))
2. The following query gets the other info. I need to merge them.
SELECT ProviderGroup.Company, ProviderGroup.NameFirst, ProviderGroup.NameLast, ProviderGroup.GroupSize, ProviderGroup.City, ProviderGroup.State,
ProviderGroup.ReferrerName , ProviderGroup.SignOnDate, ProviderGroup.Status
FROM ProviderGroup
WHERE (SignOnDate > Getdate() - 14) AND (Status = 1)
The first query returns only the Users.LoginSuccess column. The second returns the other information I need to bind to that so that the query outputs all of the following rows:
Users.LoginSuccess + ProviderGroup.Company, ProviderGroup.NameFirst, ProviderGroup.NameLast, ProviderGroup.GroupSize, ProviderGroup.City, ProviderGroup.State,
ProviderGroup.ReferrerName
1. The following query works to pull LoginSuccess values:
SELECT Users.LoginSuccess
FROM Users
WHERE Users.UserTable='Provider'
AND Users.UserTableID
IN
(SELECT Provider.ProviderID
FROM Provider
WHERE Provider.ProviderGroupID
IN (SELECT ProviderGroup.ProviderGrou
FROM ProviderGroup
WHERE (ProviderGroup.SignOnDate > Getdate() - 14)
AND ProviderGroup.Status = 1))
2. The following query gets the other info. I need to merge them.
SELECT ProviderGroup.Company, ProviderGroup.NameFirst, ProviderGroup.NameLast, ProviderGroup.GroupSize, ProviderGroup.City, ProviderGroup.State,
ProviderGroup.ReferrerName
FROM ProviderGroup
WHERE (SignOnDate > Getdate() - 14) AND (Status = 1)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.