Hi,
I have a json text in sql server. i woul like to know how to write select query for the below code .
bit confused how can we select @baseRate ,@amount.. all variables starting with @
{"HotelItineraryResponse":{"@size":"1","customerSessionId":"0AB28636-2CD6-4915-BF42-27360D9065D4","Itinerary":{"itineraryId":278985747,"affiliateId":489808,"creationDate":"01\/31\/2017","creationTime":"22:10:17 CST","itineraryStartDate":"07\/10\/2017","itineraryEndDate":"07\/17\/2017","affiliateCustomerId":"036686","Customer":{"email":"[email protected]","firstName":"Melissa","lastName":"Rodger","homePhone":"0010401162767","workPhone":"0010401162767","CustomerAddresses":{"address1":"123 Fake Road","city":"San Francisco","stateProvinceCode":"CA","countryCode":"US","postalCode":83715,"isPrimary":true,"type":1}},"HotelConfirmation":{"supplierId":13,"chainCode":"EP","arrivalDate":"07\/10\/2017","departureDate":"07\/17\/2017","confirmationNumber":135507880191,"RateInfos":{"@size":"1","RateInfo":{"@priceBreakdown":"true","@promo":"false","@rateChange":"false","ChargeableRateInfo":{"@averageBaseRate":"97.23","@averageRate":"97.23","@commissionableUsdTotal":"505.13","@currencyCode":"AUD","@maxNightlyRate":"97.23","@nightlyRateTotal":"680.61","@surchargeTotal":"127.12","@total":"807.73","NightlyRatesPerRoom":{"@size":"7","NightlyRate":{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"}},"Surcharges":{"@size":"1","Surcharge":{"@type":"TaxAndServiceFee","@amount":"127.12"}}},"cancellationPolicy":"This rate is non-refundable and cannot be changed or cancelled - if you do choose to change or cancel this booking you will not be refunded any of the payment.","nonRefundable":true,"online":true,"rateType":"MerchantPackage"}},"numberOfAdults":2,"numberOfChildren":0,"affiliateConfirmationId":"210108-0-flightcentreltd-0","smokingPreference":"N","supplierPropertyId":5405401,"roomTypeCode":200211986,"rateCode":208195741,"rateDescription":"Book now and save","roomDescription":"Deluxe Room","status":"CF","locale":"en_US","GenericRefund":{"refundAmount":"0.00","currencyCode":"USD"},"ReservationGuest":{"firstName":"Melissa","lastName":"Rodger"},"Hotel":{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},"ConfirmationExtras":{"@size":"2","ConfirmationExtra":{"@name":"ADDITIONAL_DATA_1","@value":"210108"},{"@name":"ADDITIONAL_DATA_2","@value":"557500"}},"nights":7},{"supplierId":13,"chainCode":"EP","arrivalDate":"07\/10\/2017","departureDate":"07\/17\/2017","confirmationNumber":"135507880191-1","RateInfos":{"@size":"1","RateInfo":{"@priceBreakdown":"true","@promo":"false","@rateChange":"false","ChargeableRateInfo":{"@averageBaseRate":"74.95","@averageRate":"74.95","@commissionableUsdTotal":"389.38","@currencyCode":"AUD","@maxNightlyRate":"74.95","@nightlyRateTotal":"524.65","@surchargeTotal":"98.00","@total":"622.65","NightlyRatesPerRoom":{"@size":"7","NightlyRate":{"@baseRate":"74.95","@rate":"74.95","@promo":"false"},{"@baseRate":"74.95","@rate":"74.95","@promo":"false"},{"@baseRate":"74.95","@rate":"74.95","@promo":"false"},{"@baseRate":"74.95","@rate":"74.95","@promo":"false"},{"@baseRate":"74.95","@rate":"74.95","@promo":"false"},{"@baseRate":"74.95","@rate":"74.95","@promo":"false"},{"@baseRate":"74.95","@rate":"74.95","@promo":"false"}},"Surcharges":{"@size":"1","Surcharge":{"@type":"TaxAndServiceFee","@amount":"98.00"}}},"cancellationPolicy":"This rate is non-refundable and cannot be changed or cancelled - if you do choose to change or cancel this booking you will not be refunded any of the payment.","nonRefundable":true,"online":true,"rateType":"MerchantPackage"}},"numberOfAdults":2,"numberOfChildren":0,"affiliateConfirmationId":"210108-0-flightcentreltd-0","smokingPreference":"N","supplierPropertyId":5405401,"roomTypeCode":200211986,"rateCode":208195741,"rateDescription":"Last minute deal","roomDescription":"Deluxe Room","status":"CF","locale":"en_US","GenericRefund":{"refundAmount":"0.00","currencyCode":"USD"},"ReservationGuest":{"firstName":"Melissa","lastName":"Rodger"},"Hotel":{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},"ConfirmationExtras":{"@size":"2","ConfirmationExtra":{"@name":"ADDITIONAL_DATA_1","@value":"210108"},{"@name":"ADDITIONAL_DATA_2","@value":"557500"}},"nights":7},{"supplierId":13,"chainCode":"EP","arrivalDate":"07\/10\/2017","departureDate":"07\/17\/2017","confirmationNumber":"135507880191-2","RateInfos":{"@size":"1","RateInfo":{"@priceBreakdown":"true","@promo":"false","@rateChange":"false","ChargeableRateInfo":{"@averageBaseRate":"97.23","@averageRate":"97.23","@commissionableUsdTotal":"505.13","@currencyCode":"AUD","@maxNightlyRate":"97.23","@nightlyRateTotal":"680.61","@surchargeTotal":"127.12","@total":"807.73","NightlyRatesPerRoom":{"@size":"7","NightlyRate":{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"},{"@baseRate":"97.23","@rate":"97.23","@promo":"false"}},"Surcharges":{"@size":"1","Surcharge":{"@type":"TaxAndServiceFee","@amount":"127.12"}}},"cancellationPolicy":"This rate is non-refundable and cannot be changed or cancelled - if you do choose to change or cancel this booking you will not be refunded any of the payment.","nonRefundable":true,"online":true,"rateType":"MerchantPackage"}},"numberOfAdults":1,"numberOfChildren":0,"affiliateConfirmationId":"210108-0-flightcentreltd-0","smokingPreference":"N","supplierPropertyId":5405401,"roomTypeCode":200211986,"rateCode":208195741,"rateDescription":"Book now and save","roomDescription":"Deluxe Room","status":"CF","locale":"en_US","GenericRefund":{"refundAmount":"0.00","currencyCode":"USD"},"ReservationGuest":{"firstName":"Melissa","lastName":"Rodger"},"Hotel":{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},{"hotelId":418743,"statusCode":"A","name":"Hotel Kumala Pantai","address1":"Jl. Werkudara","city":"Legian","countryCode":"ID","postalCode":80361,"phone":"62-361-755500","fax":"62-361-755700","latitude":-8.69873,"longitude":115.16501,"coordinateAccuracyCode":0,"lowRate":108.4756,"highRate":433.9054,"confidence":52,"hotelRating":3.5,"tripAdvisorRating":4.0,"theme":"Business Hotel, Family Hotel","specialCheckInInstructions":"Guests booked in the \"Domestic Rate\" category must provide Indonesian identification or a KITAS card at check-in. The hotel reserves the right to amend the room rate to full price if valid proof is not provided. In accordance with local regulations, all visitors must remain within the hotel property during Seclusion Day\/Hindu New Year on March 17, 2018 (from midnight March 16, 2018 to early morning March 18, 2018). Check-in and check-out will not be possible on March 17, 2018. For more details, please contact the office using the information on the reservation confirmation received after booking."},"ConfirmationExtras":{"@size":"2","ConfirmationExtra":{"@name":"ADDITIONAL_DATA_1","@value":"210108"},{"@name":"ADDITIONAL_DATA_2","@value":"557500"}},"nights":7}}}}
******************
below select query im using ..but not giving the whole data
DECLARE @json NVARCHAR(MAX)= (select * from tb )
SELECT *
FROM OPENJSON(@json)
WITH (
itineraryId varchar(200) '$.HotelItineraryResponse.Itinerary.itineraryId' ,
firstName varchar(50) '$.HotelItineraryResponse.Itinerary.Customer.firstName',
LastName varchar(50) '$.HotelItineraryResponse.Itinerary.Customer.lastName',
Email varchar(50) '$.HotelItineraryResponse.Itinerary.Customer.email',
arrivalDate date '$.HotelItineraryResponse.Itinerary.HotelConfirmation[0].arrivalDate',
departureDate date '$.HotelItineraryResponse.Itinerary.HotelConfirmation[0].departureDate',
--supplierId varchar(50) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.supplierId',
--priceBreakdown nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.RateInfos.RateInfo.priceBreakdown',
cancellationPolicy nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.RateInfos.RateInfo[0].cancellationPolicy',
averageRate nvarchar(50) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.RateInfos.RateInfo.ChargeableRateInfo[1].averageRate',
total money '$.HotelItineraryResponse.Itinerary.HotelConfirmation.RateInfos.RateInfo.ChargeableRateInfo.total',
surchargeTotal money '$.HotelItineraryResponseItinerary.HotelConfirmation.RateInfos.RateInfo.ChargeableRateInfo.surchargeTotal',
roomDescription nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.roomDescription',
phone nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel.phone',
name nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel.name',
[address] nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel.address1',
city nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel.city',
stateProvinceCode nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel[0].stateProvinceCode',
countryCode nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel.countryCode',
nights int '$.HotelItineraryResponse.Itinerary.HotelConfirmation[0].nights',
numberOfChildren int '$.HotelItineraryResponse.Itinerary.HotelConfirmation[0].numberOfChildren',
numberOfAdults int '$.HotelItineraryResponse.Itinerary.HotelConfirmation[0].numberOfAdults',
specialCheckInInstructions nvarchar(max) '$.HotelItineraryResponse.Itinerary.HotelConfirmation.Hotel.specialCheckInInstructions'
)
|