Question

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
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top