I am having a problem with my filestream filetable, when I run an insert statement on it the file saves, but the file_type column is null (and obviously cannot be updated manually given that it's a computed column)
DECLARE @counter INT, @maxPolicySectionId INT
DECLARE @name NVARCHAR(128)
DECLARE @file_stream VARBINARY(MAX)
DECLARE @path NVARCHAR(256)
DECLARE @command NVARCHAR(MAX)
DECLARE @fileTable TABLE(
name NVARCHAR(50),
filePath NVARCHAR(128),
polSecId INT
);
--...Populate @fileTable from database table...--
SELECT @counter = MIN(policySectionId), @maxPolicySectionId = MAX(policySectionId) FROM tblPolicySection
SET @name = (SELECT name FROM @fileTable WHERE polSecId = @counter)
SET @path = (SELECT filePath FROM @fileTable WHERE polSecId = @counter)
SET @path = REPLACE(@path, '192.168.0.6', 'meta-filesrv')
--SET @file_type in Filetable somehow.. unable to perform UPDATE because it's a computed column
SET @command = N'SELECT @file_stream1 = CAST(bulkcolumn AS varbinary(MAX))
from OPENROWSET(BULK ''' + @path + ''',
SINGLE_BLOB) AS x'
EXEC sp_executesql @command, N'@file_stream1 VARBINARY(MAX) OUTPUT',@file_stream1 = @file_stream OUTPUT
IF @path IS NOT NULL AND @name IS NOT NULL
BEGIN
INSERT INTO BlobDocStore(
name,
file_stream
)
SELECT
@name,
@file_stream
END
SET @counter = @counter + 1
As you can see I am passing a stream into the insert statement which should work to the best of my understanding. I'm hoping someone has had some experience with this in the past. Thanks.