SQL script to insert Word document Into a SQL Server 2005 table

假装没事ソ 提交于 2019-12-25 07:46:51

问题


I have to import some Word documents into a SQL Server database. This has to be done all in SQL no C# code or little app to do it.

I have been googling how to do it but i cannot find a single example how to do it.

Lets suppose I have

  1. a Word file called MyDoc.doc
  2. A table called Documents with Id=autogenerated, DocName varchar(255) and DocContent (Varbinary(Max))

How do I insert my MyDoc.doc into my table using just SQL?

Many thanks

updated

DECLARE @BinarySample IMAGE
SET @BinarySample=(SELECT BulkColumn 
    FROM OPENROWSET(BULK N'C:\mydoc.docx', SINGLE_BLOB)  blob)

SELECT @BinarySample


 EXEC [dbo].MyStoredProc @BinaryColumn =@BinarySample

回答1:


You can use something like this:

INSERT INTO dbo.Documents(DocName, DocContent)
   SELECT
       'C:\tmp\mydoc.doc', 
       BulkColumn
   FROM
       OPENROWSET(BULK N'C:\tmp\mydoc.doc', SINGLE_BLOB) blob


来源:https://stackoverflow.com/questions/22435222/sql-script-to-insert-word-document-into-a-sql-server-2005-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!