XML 値 (例: 0.19) を INT にキャストし、* 100 で計算しようとしています。
しかし、次のようなエラーが表示されます: INT タイプの nvarchar-Value '0.19' を変換することによるエラー。
これはコードです: (ただし、「CAST」のある行が問題です)
insert into BELEGP(Kennung, Belegtyp, Belegnummer, Posnummer, Postext, Zeilentyp, Menge, Steuerprozent, Eingabemenge, Editmenge, Artikelnummer, Bezeichnung, Preismenge, Einzelpreis, Gesamtpreis, Netto, Adressnr)
SELECT NEWID() as Kennung,
'F' as Belegtyp,
Myorder.j.value('OrderNumber[1]', 'varchar(50)') as Belegnummer,
ROW_NUMBER() OVER (ORDER BY Myorder.j.value('OrderNumber[1]', 'varchar(50)')) as Posnummer,
ROW_NUMBER() OVER (ORDER BY Myorder.j.value('OrderNumber[1]', 'varchar(50)')) as Postext,
'A' as Zeilentyp,
MyItem.j.value('Quantity[1]', 'varchar(50)') as Menge,
CAST(Cast(MyItem.j.value('TaxRate[1]', 'nvarchar(50)') as nvarchar) as INT) * 100 as Steuerprozent,
MyItem.j.value('Quantity[1]', 'varchar(50)') as Eingabemenge,
MyItem.j.value('Quantity[1]', 'varchar(50)') as Editmenge,
MyItem.j.value('Id[1]', 'varchar(50)') as Artikelnummer,
MyItem.j.value('Name[1]', 'varchar(50)') as Bezeichnung,
MyItem.j.value('TotalPrice[1]', 'varchar(50)') as Preismenge,
MyItem.j.value('TotalPrice[1]', 'varchar(50)') as Einzelpreis,
MyItem.j.value('TotalPrice[1]', 'varchar(50)') as Gesamtpreis,
MyItem.j.value('UnityPrice[1]', 'varchar(50)') as Netto,
Myorder.j.value('CustomerNumber[1]', 'varchar(50)') as Adressnr
FROM (
SELECT CAST(x AS XML)
FROM
OPENROWSET( BULK 'D:\shop\xml\Bestellungen.xml',SINGLE_BLOB) AS k(x))
AS k(x)
CROSS APPLY x.nodes('Orders/Order') AS MYorder(j)
CROSS APPLY x.nodes('Orders/Order/Addresses/BillingAddress') AS MYAddresses(j)
CROSS APPLY x.nodes('Orders/Order/LineItems/LineItem') AS MYItem(j)