Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Trying to get the correct county when it is in 2 different tables

$
0
0

I have the query below and the county isn't working. Any help is greatly appreciated.  The county table has the actual name which is what I need.

SELECT	o.ObservationID,		
	(CASE WHEN st.SiteName = 'My Site'
		THEN (SELECT County FROM County WHERE sc.CountyID = County.CountyID)
		ELSE (SELECT County FROM County WHERE s.SiteID = County.CountyID)
	END) AS County				 		
FROM Observation o
	LEFT JOIN ObservationPermit p ON o.ObservationID = p.ObservationID
	LEFT JOIN ObservationSite s ON o.ObservationID = s.ObservationID
	LEFT JOIN [Site] st ON s.SiteID = st.SiteID
	LEFT JOIN SiteCounty sc ON st.SiteID = sc.SiteID	
	LEFT JOIN County c ON sc.CountyID = c.CountyID 			
WHERE ProjectID = 103 


*** Please allow me to mark threads as answered and I will, Thank you ***


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>