のノードを検出する私は、以下のようなXMLファイルから読み込み、その値をフォームの関連フィールドにインポートするSQLトリガーを持っています。SQLを使用してフィールド値が
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2016-08-18T07:03:22">
<MPSExport>
<ReportID>WR_2245</ReportID>
<ActivityID>0</ActivityID>
<Hours>13.75</Hours>
</MPSExport>
<MPSExport>
<ReportID>WR_2245</ReportID>
<ActivityID>115810</ActivityID>
<Method>5</Method>
<Herbicide_1>5</Herbicide_1>
<Herbicide_Rate_1>0.05</Herbicide_Rate_1>
<Herbicide_Qty_1>20</Herbicide_Qty_1>
<Herbicide_2>2</Herbicide_2>
<Herbicide_Rate_2>0.5</Herbicide_Rate_2>
<Herbicide_Qty_2>60</Herbicide_Qty_2>
<Herbicide_IsSurfactant_2>1</Herbicide_IsSurfactant_2>
<Comments>Test.</Comments>
</MPSExport>
<MPSExport>
<ReportID>WR_2245</ReportID>
<ActivityID>115810</ActivityID>
<Method>8</Method>
<Herbicide_1>10</Herbicide_1>
<Herbicide_Rate_1>2</Herbicide_Rate_1>
<Herbicide_Qty_1>30</Herbicide_Qty_1>
<Herbicide_2>2</Herbicide_2>
<Herbicide_Rate_2>1</Herbicide_Rate_2>
<Herbicide_Qty_2>70</Herbicide_Qty_2>
<Herbicide_IsSurfactant_2>1</Herbicide_IsSurfactant_2>
<Weed_1>5266</Weed_1>
<Weed_2>5261</Weed_2>
<Weed_3>5884</Weed_3>
<Weed_4>4004</Weed_4>
<Comments>WR_2245 finished off some of WMA_620's budget (MPS BLM Bal Est BC). Began treating rambling dock and winter cherry.</Comments>
<FollowUpNotes>Continue to work through the Zone</FollowUpNotes>
</MPSExport>
</dataroot>
同じ名前で繰り返されるフィールドがあるため、フォーム上の異なるタブのフィールドに対応します。誰かがXMLファイルに空白「メソッド」フィールドの最初の発生を離れるが、第2の発生が値を持っている場合は、これらを区別するために、私は、
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 100)) AS ROW, 'Method', CAST([Method]AS VARCHAR(2)) FROM OPENXML(@hDoc, 'dataroot/MPSExport') WITH ([Method] [nvarchar](max) 'Method') WHERE [Method] IS NOT NULL
UNION ALL.....continue with other fields
問題があるを使用し、私のインポートプロセスは、最初のメソッドフィールドに移入されますXMLファイル内の2番目のMethod値を持つフォーム上に配置します。
フィールド名を繰り返してグループ化するのではなく、親ノードがXMLフィールドをグループ化する方法がありますか?つまり、MPSExport?
は、一つのフィールド上のテストとして、私は
SELECT 'Method', CAST([Method]AS VARCHAR(2)),
ROW_NUMBER() OVER (ORDER BY T.X) AS ROW
FROM @XML.nodes('dataroot/MPSExport') AS T(X)
CROSS APPLY
OPENXML(@hDoc, 'dataroot/MPSExport') WITH ([Method] [nvarchar](max) 'Method')
WHERE [Method] IS NOT NULL
を試してみましたが、私はそれが
Method 5 2
Method 8 3
5と8ですが見せたいのに対し、それはちょうど私に次
Method 5 1
Method 8 2
Method 5 3
Method 8 4
Method 5 5
Method 8 6
を与えます値、2と3はMPSExportノードのオカレンスです。 これは可能ですか?
お返事ありがとうございました。私はトリガーを更新します。非常に役立ちます。 – user3882865