Bulk insert images into SQL Server database -
i want insert images in way:
declare @lpath varchar(100) set @lpath = 'd:\photo\5604.jpg' --insert photos(id, photo, path) select 4144, *, @lpath openrowset(bulk @lpath, single_blob) but it's not working
if execute code this:
select 1, *, @lpath openrowset(bulk n'd:\photo\5604.jpg', single_blob) it works well.
how execute script in first way?
you cannot use variables in openrowset, try use dynamic sql this:
declare @lpath nvarchar(100) set @lpath = 'd:\photo\5604.jpg' declare @sql nvarchar(max) set @sql='select 4144, *, ''' + @lpath + ''' openrowset(bulk ''' + @lpath + ''', single_blob) i' exec(@sql)
Comments
Post a Comment