Solved

varbinary(max) filestream - how to insert/reference file location?

Posted on 2011-09-02
4
455 Views
Last Modified: 2012-05-12
I have the below table - when I use the below insert - and then set a full text index - it is apparent, it is just storing the file name or something as when I check the indexed words - only the document name is indexed - so my question is - when trying to use filestream and varbinary(max) - is the simple example below correct?

CREATE TABLE cptDocuments(
  [docID] [int] IDENTITY(1,1) NOT NULL,
  [document] varbinary(max) FILESTREAM NULL,
  [docExtension] varchar(30),
  [RowGuid] UNIQUEIDENTIFIER NOT NULL  ROWGUIDCOL UNIQUE DEFAULT NEWID(),
CONSTRAINT [PK_cptDocuments_docID] PRIMARY KEY CLUSTERED
(
  [docID] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

INSERT INTO cptDocuments(Document, [docExtension]  )
VALUES (
CAST('C:\inetpub\wwwroot\PDE\CPTAssistant\Archives\Updated Reporting Instruction for Hydration Infusion (Code 90760).htm' as varbinary(max))
,'.htm'
)
0
Comment
Question by:tbaseflug
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:tknudsen-qec
ID: 36475072
Short answer, no.  

INSERT INTO cptDocuments(Document)
    SELECT *
    FROM OpenRowSet(BULK N'C:\inetpub\wwwroot\PDE\CPT....', SINGLE_BLOB) AS Document

You can also drop it into a variable thusly:

DECLARE @mybinary VARBINARY(MAX)
SELECT @mybinary = BulkColumn
FROM OPENROWSET(BULK N'C:\inetpub\wwwroot\PDE\CPT....', SINGLE_BLOB) AS Document

And then insert that.

HTH
0
 

Author Comment

by:tbaseflug
ID: 36475090
is there a way - say after I do that or during that - to put in a few other variables - such as 'file name here.htm' and '.htm' - the file name and the extension - as part of that insert statement in openrowset?
0
 
LVL 3

Accepted Solution

by:
tknudsen-qec earned 500 total points
ID: 36475127
Absolutely.  Its particularly clear with the second example, since you can insert your extensions PLUS the variable:

INSERT INTO MyTable (ExtensionColumn, BinaryColumn) VALUES ('.htm', @myBinary)


But with the first example, that "SELECT *" only returns one column (BulkColumn).  You could also:
"SELECT *, '.htm' as extension"
if you like.  

If I'd been using both my braincells I would have used BulkColumn in both examples.
0
 

Author Closing Comment

by:tbaseflug
ID: 36475191
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question