Patrice Pezillier
Patrice Pezillier

Reputation: 4566

Upload a file to a varbinary with SQL Management Studio

Is there any way to upload a file to a varbinary with SQL Management Studio without writting a manual SQL query ?

Upvotes: 13

Views: 10082

Answers (2)

John Sansom
John Sansom

Reputation: 41849

In short, using SQL Server Management Studio (SSMS), no.

The options are to either complete your task via T-SQL or to roll your own solution/application.

A solution devised using SQL Server Integration Services (SSIS) may also be possible.

Upvotes: 7

SQLMenace
SQLMenace

Reputation: 135021

use OPENROWSET

example

USE AdventureWorks2008R2;
GO
CREATE TABLE myTable(FileName nvarchar(60), 
  FileType nvarchar(60), Document varbinary(max));
GO

INSERT INTO myTable(FileName, FileType, Document) 
   SELECT 'Text1.txt' AS FileName, 
      '.txt' AS FileType, 
      * FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document;
GO

Upvotes: 17

Related Questions