SQL Server:从多个jpeg文件的jpeg文件更新二进制数据

时间:2019-04-03 18:47:32

标签: sql-server

我有一个包含两列的表import { trigger, animate, transition, style, state } from '@angular/animations'; export const buttonFadeIn = trigger('buttonFadeIn', [ state('in', style({ opacity: 1, })), transition("* => in", animate('500ms ease-in-out')), state('out', style({ opacity: 0, })), transition("* => out", animate('220ms ease')) ]);

  • IMAGE数据类型varchar(50)-包含jpeg文件路径
  • IMG数据类型图片

我需要将guest列的所有记录更新为IMG列中提到的位置中存在的二进制数据。

IMAGE

此SQL语句一次将仅更新一个记录。但是我需要将每个记录的与jpeg文件对应的所有记录更新为UPDATE guest SET img = (SELECT bulkcolumn FROM OPENROWSET(BULK N'D:\Webcam Images\24092018071230.jpg', SINGLE_BLOB) AS X) WHERE ID = 53 数据类型列Image

1 个答案:

答案 0 :(得分:0)

我无法直接测试此代码,但是类似的事情应该起作用(您也可以将其重写为游标,添加错误检查等):

create table #guest (
    ID int,
    FilePath varchar(50),
    FileImage image,
    Updated tinyint
)

insert into #guest (ID, FilePath, FileImage, Updated)
    select ID, Image, IMG, 0
    from guest

declare @sql varchar(1500), @FilePath varchar(50), @ID int

while exists (select top 1 ID from #guest where Updated = 0)
begin

    select top 1 @ID = ID, @FilePath = FilePath from #guest where Updated = 0

    select @sql = 'update #guest set FileImage = ' + '(select bulkcolumn from openrowset(bulk n''' + @FilePath + ', SINGLE_BLOB) AS X) where ID = ' + @ID

    exec sp_executesql @sql

    update #guest set Updated = 1 where ID = @ID

end

update g
set g.IMG = #guest.FileImage
from guest g
inner join #guest on g.ID = #guest.ID