tailieunhanh - Hướng dẫn học Microsoft SQL Server 2008 part 51

Mặc dù các phần tử gốc là chính xác nhất, sản lượng XML không phải trong cơ cấu cần thiết. Trong thực tế, thông tin đưa ra là không chính xác, bởi vì nó cho thấy rằng tất cả ba mục hàng thuộc SO102 đặt hàng. Hành vi này là do thực tế là các máy phát điện XML tiêu thụ hàng trong thứ tự như chúng được trả về bởi các truy vấn SELECT. Để tạo ra các kết quả theo trình tự chính xác, các truy vấn SELECT nên có một ORDER BY khoản điều khiển thứ tự. | Part III Beyond Relational LineItems ItemNo D001 Qty 1 Order Orders Though the root element is correctly added the XML output is not in the required structure. In fact the information given is incorrect because it shows that all three line items belong to Order SO102. This behavior is caused by the fact that the XML generator consumes rows in the same order as they are returned by the SELECT query. To generate the results in the correct order the SELECT query should contain an ORDER BY clause that controls the order of the rows in the result set. The following example shows a new version of the query that generates a column just for the purpose of sorting. It then uses the HIDE directive to instruct SQL Server that the column should not be included in the XML output SELECT 1 AS Tag NULL AS Parent CustomerNumber AS Order 1 CustNo OrderNumber AS Order 1 OrderNo REPLACE STR OrderID 4 STR 0 4 0 AS Order 1 Sort HIDE NULL AS LineItems 2 ItemNo NULL AS LineItems 2 Qty FROM OrderHeader o INNER JOIN Customers c ON UNION ALL SELECT 2 AS Tag 1 AS Parent NULL NULL REPLACE STR OrderID 4 STR OrderDetailID 4 0 FROM Items i INNER JOIN OrderDetails o ON ORDER BY Order 1 Sort HIDE FOR XML EXPLICIT ROOT Orders Orders Order CustNo J001 OrderNo SO101 LineItems ItemNo D001 Qty 1 LineItems ItemNo Z001 Qty 1 Order Order CustNo J001 OrderNo SO102 LineItems ItemNo D001 Qty 1 Order Orders 462 Manipulating XML Data 18 That query could produce the correct result because of the ORDER BY clause present in the query. The ORDER BY clause ensures that the first row is the order header information for SO101 and that the next two rows contain order detail information for the same order. Again it ensures that the next row is order header information for SO102 followed by the order detail information of the same order. The query returns the following result set column names abridged for space Tag Parent CustNo .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.