我正在尝试将两个图像插入到我的SQL Server 2012数据库中。插入一个图像有效,但插入两个图像不起作用:
插入一张图片:
BEGIN TRY
SET @sql = 'INSERT INTO [dbo].[PicturesCamera1] (Name, [OriginalBitmap])
SELECT ''' + @CameraPicture1 + ''',
BulkColumn FROM Openrowset(Bulk''' + @ImagePath + @CameraPicture1 + '.bmp' + ''', Single_Blob) as Pic'
INSERT INTO #tmpBus
EXEC sp_executesql @sql
END TRY
BEGIN CATCH
SET @resulttext = 'File not found. Picture seems not to be available on camera 1 cache any more.';
END CATCH
插入两张图片:
BEGIN TRY
SET @sql = 'INSERT INTO [dbo].[PicturesCamera1] (Name, [OriginalBitmap], [PreviewJpg])
SELECT ''' + @CameraPicture1 + ''',
BulkColumn FROM Openrowset(Bulk''' + @ImagePath + @CameraPicture1 + '.bmp' + ''', Single_Blob) as Pic,
BulkColumn FROM Openrowset(Bulk''' + @ImagePath + @CameraPicture1 + '.jpg' + ''', Single_Blob) as Pic2'
INSERT INTO #tmpBus
EXEC sp_executesql @sql
END TRY
BEGIN CATCH
SET @resulttext = 'File not found. Picture seems not to be available on camera 1 cache any more.';
END CATCH
答案 0 :(得分:0)
试试吧
INSERT INTO [PicturesCamera1] (Name, [OriginalBitmap], [PreviewJpg])
SELECT
'...',
(SELECT BulkColumn FROM Openrowset(Bulk '...', Single_Blob) q) Pic1,
(SELECT BulkColumn FROM Openrowset(Bulk '...', Single_Blob) q) Pic2