troubleshooting Question

Column Alias Names and UNION error

Avatar of bendecko
bendecko asked on
Microsoft SQL Server
4 Comments1 Solution795 ViewsLast Modified:
Hi

I need to execute this SQL

SELECT NULL AS 'county' UNION select distinct [county/department] as county from COUK_hotels WHERE source = 'activehotels' AND [county/department] NOT LIKE '%london%' group by [county/department] having count([county/department]) > 5 order by [county/department]

The first part is to shove a first result 'NULL' into the result set.  Don't ask me why - the ASP code just needs it ok!

If I run each query separately it works fine:

SELECT NULL AS 'county'

and

select distinct [county/department] as county from COUK_hotels WHERE source = 'activehotels' AND [county/department] NOT LIKE '%london%' group by [county/department] having count([county/department]) > 5 order by [county/department]

But when combined I get an error Invalid column name 'county/department'.

Is there some way of encasing the query with some characters to avoid this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros