Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Created September 26, 2024 21:22
Show Gist options
  • Save dontpaniclabsgists/172f57da75a8ac2f2c74ad6697be61ef to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/172f57da75a8ac2f2c74ad6697be61ef to your computer and use it in GitHub Desktop.
StringBuilder query = new StringBuilder($";With fullTable as (select b.[Id],[BusinessName], ");
// manipulate data
query.Append($"CAST(CASE WHEN COUNT(service.BusinessId)>0 THEN 1 ELSE 0 END AS bit) as servicesFlag")
query.Append($" from [DB].[Businesses] b ");
// add data to table that is needed for line 2 to execute properly
query.Append($"LEFT JOIN [DB].Services service ON service.BusinessId = b.Id ");
Data = db.Businesses.FromSqlRaw(query.ToString()).ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment