Skip to content

Instantly share code, notes, and snippets.

@garfbradaz
Created April 27, 2018 15:02
Show Gist options
  • Save garfbradaz/e3fb3eb7323734a1916ff9f9e7fecc59 to your computer and use it in GitHub Desktop.
Save garfbradaz/e3fb3eb7323734a1916ff9f9e7fecc59 to your computer and use it in GitHub Desktop.
Example query to CosmosDB
SELECT DISTINCT CAST(edt.[EditionID] AS varchar) AS editionId
,edt.[CoverTitle] AS coverTitle
,edt.[ISBN13] AS isbn13
,edt.[SubTitle] AS subTitle
,edt.[CoverAuthors] AS coverAuthors
,edt.[WorkReference] AS workReference
,edt.[Binding] AS binding
,edt.[Division] AS division
,edt.[Format] AS format
,edt.[SortTitle] AS sortTitle
,edt.[WorkID] AS workId
,edt.[Imprint] AS imprint
,edt.[Pubdate] AS pubDate
,edt.[CreatedDate] AS [CreatedDate]
,edt.[UpdatedDate] AS [UpdatedDate]
, (
select '[' + STUFF((
select
',{"id":' + cast(edt2.Id as varchar(max))
+ ',"code":"' + edt2.Code + '"'
+ ',"description":"' + edt2.Full_Description + '"'
+ ',"version":"' + edt2.Version + '"'
+'}'
from [somedb].[dbo].[sometable] as edt2
where edt.EditionId = edt2.EditionID
for xml path(''), type
).value('.', 'varchar(max)'), 1, 1, '') + ']'
) as biccodes
FROM [somedb].[dbo].[sometable] AS edt
LEFT JOIN [somedb].[dbo].[anothertable] AS grp ON edt.editionId = grp.editionId
where edt.editionId = 17311
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment