Created
May 6, 2020 21:05
-
-
Save StefanRiedmann/f50ebe98908309646dbb6cb9f18186d6 to your computer and use it in GitHub Desktop.
SQL Query to get crop information per garden and year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select distinct | |
Gardens.GardenId | |
, Gardens.Name | |
, ca.Year | |
,substring( | |
( | |
select ' | '+Crops.Name as [text()] | |
from Crops | |
join CropAssignments on Crops.CropId = CropAssignments.CropId | |
join Beds on Beds.BedId = CropAssignments.BedId | |
where Beds.GardenId = Gardens.GardenId and ca.[Year] = CropAssignments.[Year] | |
order by Crops.Name | |
FOR XML PATH ('') | |
), 4, 1000) as AllGardenCrops | |
from Gardens | |
join Beds on Beds.GardenId = Gardens.GardenId | |
join CropAssignments as ca on ca.BedId = Beds.BedId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment