QuestionQ29

Design and develop database solutions

You have an Azure SQL database named SalesDB that contains tables named Sales.Orders and Sales.OrderLines. Both tables hold sales data.

A Retrieval Augmented Generation (RAG) service queries SalesDB to retrieve order details and passes the results to a large language model (LLM) as JSON text. The following is a simple example of the JSON.

Question Image

You need to return one JSON document per order that includes the order header fields and an array of related order lines. The LLM must receive a single JSON array of orders, where each order contains a lines property that is a JSON array of line items.

Which Transact-SQL commands should you use to produce the required JSON shape from the relational tables? Each command may be used once, more than once, or not at all.

Drag & Drop
Serialize the order-level JSON:
Generate a nested lines array:
Extract a single scalar value from the JSON text:
Explanation

FOR JSON PATH serializes relational query results as JSON. Using it in a correlated subquery produces each order’s nested lines array, and using it on the outer query produces the JSON array of orders. JSON_VALUE extracts a single scalar value from JSON text.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!