将映像批量插入SQL Server数据库 [英] Bulk insert images into SQL Server database
本文介绍了将映像批量插入SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以这种方式插入图像:
I want to insert images in this way:
DECLARE @lpath varchar(100)
SET @lpath = 'd:\Photo\5604.jpg'
--insert into Photos(id, Photo, Path)
SELECT
4144, *, @lpath
FROM
OpenRowSet(BULK @lpath, Single_blob) AS i
但它不起作用
如果我执行这样的代码:
If I execute the code like this:
SELECT
1, *, @lpath
FROM
OpenRowSet(BULK N'd:\Photo\5604.jpg', Single_blob) AS i
效果很好。
如何以第一种方式执行脚本?
How to execute script like in the first way?
推荐答案
您不能在 OpenRowSet
中使用变量,请尝试使用像这样的动态SQL:
You cannot use variables in OpenRowSet
, try to use dynamic SQL like this:
DECLARE @lpath NVARCHAR(100)
SET @lpath = 'd:\Photo\5604.jpg'
DECLARE @sql NVARCHAR(MAX)
SET @sql='SELECT 4144, *, ''' + @lpath + '''
FROM OpenRowSet(BULK ''' + @lpath + ''', Single_blob) AS i'
EXEC(@sql)
这篇关于将映像批量插入SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文