我的文件流文件表有问题,当我在其上运行一个insert语句时,文件保存,但file_type列为null(显然无法手动更新,因为它是计算列)
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
正如您所看到的,我正在将一个流传递给insert语句,该语句应尽我所能。我希望有人在过去有过这方面的经验。感谢。
答案 0 :(得分:2)
file_type派生自指定的文件名。如果file_type列为NULL
,则表明@name值没有文件扩展名。