Kommunikatsiyalarini rivojlantirish vazirligi muhammad al-xorazmiy nomidagi toshkent axborottexnologiyalari universiteti


SELECT CustomerName as Name, PhoneNumber as [Contact.Phone], FaxNumber as [Contact.Fax] FROM


Download 356.68 Kb.
bet10/20
Sana28.10.2023
Hajmi356.68 Kb.
#1729149
1   ...   6   7   8   9   10   11   12   13   ...   20
Bog'liq
XML va malumotlar bazasi mustaqil ish Mirzaqulov Nazarbek

SELECT CustomerName as Name, PhoneNumber as [Contact.Phone], FaxNumber as [Contact.Fax]
FROM Sales.Customers
WHERE CustomerID = 931
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER

Ushbu so'rov natijasi quyidagicha.


{
"Name":"Nada Jovanovic",


"Contact":{
"Phone":"(215) 555-0100",
"Fax":"(215) 555-0101"
}
}

Ushbu misolda biz massiv o'rniga bitta JSON obyektini WITHOUT_ARRAY_WRAPPER parametrini ko'rsatib berdik. Ushbu parametr so'rov natijasi bitta obyekt ekanligini bilganingizda foydalanish mumkin.


FOR JSON operatorining asosiy qiymati shundan iboratki, u JSON obyektlari yoki JSON massivi sifatida joylashtirilgan murakkab iyerarxik ma'lumotlarni ma'lumotlar bazasidan qaytarishga imkon beradi. Quyidagi misol Customerga tegishli bo'lgan Orders jadvalidan qatorlarni Orders obyektlarining joylashtirilgan qatori sifatida qanday qo'shish kerakligini ko'rsatmoqda.

select CustomerName as Name, PhoneNumber as Phone, FaxNumber as Fax,


Orders.OrderID, Orders.OrderDate, Orders.ExpectedDeliveryDate
from Sales.Customers Customer
join Sales.Orders Orders
on Customer.CustomerID = Orders.CustomerID
where Customer.CustomerID = 931
FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER

Mijoz ma'lumotlarini olish uchun alohida so'rovlarni yuborish va keyin mos keladigan Customer ro'yxatini olish o'rniga, quyida keltirilgan namunada ko'rsatilganidek, bitta so'rov bilan kerakli barcha ma'lumotlarni olishingiz mumkin.


{
"Name":"Nada Jovanovic",


"Phone":"(215) 555-0100",
"Fax":"(215) 555-0101",
"Orders":[
{"OrderID":382,"OrderDate":"2013-01-07","ExpectedDeliveryDate":"2013-01-08"},
{"OrderID":395,"OrderDate":"2013-01-07","ExpectedDeliveryDate":"2013-01-08"},
{"OrderID":1657,"OrderDate":"2013-01-31","ExpectedDeliveryDate":"2013-02-01"}
]
}



Download 356.68 Kb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   ...   20




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling