Link to home
Start Free TrialLog in
Avatar of gtrapp
gtrapp

asked on

Need help with using the UNION to union two SELECT statements

I have the two SELECT statements that work great when executed alone. I need to union them so I have the 2 results combined and returned as 1. When I use UNION for the 2 SELECTS, I get the follow error:

Msg 207, Level 16, State 3, Line 1
Invalid column name 'tBirthDate'.
Msg 207, Level 16, State 3, Line 1
Invalid column name 'tBirthDate'.

Here is the complete statements

Select cType as Type,
cDesc as Description,
CONVERT(varchar(2),
MONTH(dtEvent)) + ' - ' + CONVERT(varchar(2), DAY(dtEvent)) as Date,
month(dtEvent) as Month
from dbo.Events
union
SELECT 'Birthday' as Type,
ISNULL(cNickName, cFirstName) + ' ' + ISNULL(cLastName, '') + ' ' + ISNULL(cSuffix, '') AS Description,
CONVERT(varchar(2),
MONTH(tBirthDate)) + ' - ' + CONVERT(varchar(2), DAY(tBirthDate)) AS Date,
month(tBirthDate) as Month
FROM         dbo.PEOPLE
WHERE     (MONTH(tBirthDate) = month(getdate()) OR
MONTH(tBirthDate) = (month(getdate())+1)) AND (bHideBirthdate = 0) AND (nStatusUID = 75)
ORDER BY MONTH(tBirthDate), DAY(tBirthDate)

Can you help me with this getting it working?
SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gtrapp
gtrapp

ASKER

Yes.

I am thinking that it could be data type of the column. Having two different data types will not make the UNION work.