Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用循环将图像文件插入SQL Server表_Sql_Sql Server_Tsql - Fatal编程技术网

使用循环将图像文件插入SQL Server表

使用循环将图像文件插入SQL Server表,sql,sql-server,tsql,Sql,Sql Server,Tsql,我正在尝试起草一个SQL脚本,该脚本将循环将图像文件插入基于ID匹配的SQL Server表中。我已根据数据库中的customerID命名了图像文件。我想找出一种方法来循环遍历成员ID并将图像插入到我的表中。下面是我当前的代码 Declare @CUSTCD int, @EVENTCD nvarchar(50), @SIGNATURES varbinary(max) SET @SIGNATURES = Select BulkColumn from Openrowset (Bulk 'C

我正在尝试起草一个SQL脚本,该脚本将循环将图像文件插入基于ID匹配的SQL Server表中。我已根据数据库中的
customerID
命名了图像文件。我想找出一种方法来循环遍历成员ID并将图像插入到我的表中。下面是我当前的代码

Declare @CUSTCD int, @EVENTCD nvarchar(50), @SIGNATURES varbinary(max)    

SET @SIGNATURES = Select BulkColumn from Openrowset (Bulk 'C:\sigs\'+ @CUSTCD int+ '.png', Single_Blob) as Image


-- declare a cursor
DECLARE insert_cursor CURSOR FOR 
select @CUSTCD,'75thCelebration', BulkColumn from Openrowset (Bulk 'C:\sigs\'+(Select @CUSTCD from CUS)+'119.png', Single_Blob) as Image
--SELECT CUSTCD , EVENTCD, SIGNATURES  from CUS_SIGS2
--WHERE CUSTCD = 78

-- open cursor and fetch first row into variables
OPEN insert_cursor
FETCH NEXT FROM insert_cursor into @CUSTCD, @EVENTCD, @SIGNATURES

-- check for a new row
WHILE @@FETCH_STATUS=0
BEGIN
-- do complex operation here
Insert into CUS_SIGS2   
SELECT @CUSTCD, @EVENTCD, @SIGNATURES
-- get next available row into variables
FETCH NEXT FROM insert_cursor into @CUSTCD, @EVENTCD, @SIGNATURES
END
close insert_cursor
Deallocate insert_cursor
GO

最好创建一个简单的powershell脚本。出于安全考虑,不建议使用xp_cmdshell访问文件系统。听起来您想要的是使用。能否提供一个示例?最好创建一个简单的powershell脚本。出于安全考虑,不建议使用xp_cmdshell访问文件系统。听起来您想要的是使用。您能提供一个示例吗?
Create table #tmp
(
    SalesOrderID int,
    OrderQty int
)
GO
--simple cursor in sql server 
Declare @orderid int, @orderqty int
-- declare a cursor
DECLARE insert_cursor CURSOR FOR 
SELECT SalesOrderId,OrderQty from Sales.SalesOrderDetail
WHERE SalesOrderID=43659

-- open cursor and fetch first row into variables
OPEN insert_cursor
FETCH NEXT FROM insert_cursor into @orderid,@orderqty

-- check for a new row
WHILE @@FETCH_STATUS=0
BEGIN
-- do complex operation here
Insert into #tmp
SELECT @orderid,@orderqty
-- get next available row into variables
FETCH NEXT FROM insert_cursor into @orderid,@orderqty 
END
close insert_cursor
Deallocate insert_cursor
GO