sql >> データベース >  >> Database Tools >> SSMS

XMLをSQLServerテーブルにフィードする

    これが調整された動作SQLです。準備ができたら、INSERT行のコメントを外してください。

    SQL

    WITH XmlFile (xmlData) AS
    (
       SELECT CAST(BulkColumn AS XML) 
       FROM OPENROWSET(BULK 'C:\Users\cj\Documents\EodBalance.xml', SINGLE_BLOB) AS x
    )
    --INSERT INTO [dbo].[EndofDay] 
    --([PouchID], [Lane], [BusinessDay], BusinessStartingTime, BusinessEndingTime, [StartingBalance], [EndingBalance])
    SELECT c.value('(PouchId/text())[1]', 'VARCHAR(25)') AS [PouchId]
       , c.value('(Lane/text())[1]', 'NCHAR(2)') AS [Lane]
       , c.value('(BusinessDay/text())[1]', 'DATE') AS [BusinessDay]
       , c.value('(BusinessStartingTime)[1]', 'datetime') AS [BusinessStartingTime]
       , c.value('(BusinessEndingTime/text())[1]', 'datetime') AS [BusinessEndingTime]
       , c.value('(StartingBalance/text())[1]', 'MONEY') AS [StartingBalance]
       , c.value('(EndingBalance/text())[1]', 'MONEY') AS [EndingBalance]
    FROM XmlFile CROSS APPLY xmlData.nodes('/ArrayOfSafeEODBalance/SafeEODBalance') AS t(c);
    


    1. SQL ServerManagementStudioのスキン/外観/レイアウト

    2. Windows7でのSQLServerManagementStudioローカルデータベース接続エラー

    3. SQL Server:切り離された/破損したデータベースをアタッチ/修復する方法は?

    4. MySQLアップデートは制限付きで結合します