I want to store signatures in a SQL Server database table as VARBINARY(MAX). I use the following T-Sql to insert a signature:
INSERT INTO Signatures (UserID_FK, [Signature])
SELECT 2, BulkColumn
FROM OPENROWSET
(
Bulk 'C:\Z_KB\SignatureTest.PNG', SINGLE_BLOB
) AS [Signature]
I want to turn this into a stored procedure, but it is not happy with the following:
CREATE PROCEDURE Insert_Signatures_SP
(
@SignatureUri NVARCHAR(1000),
@UserID INT
)
AS
INSERT INTO Signatures (UserID_FK, [Signature])
SELECT @UserID, BulkColumn
FROM OPENROWSET
(
Bulk @SignatureUri, SINGLE_BLOB
) AS [Signature]
GO
It is complaining that BulkColumn is invalid column name and it is looking for a string near Bulk.
I have changed it to the following, but now it says that @UserID must be declared:
CREATE PROCEDURE Insert_Signatures_SP
(
@SignatureUri NVARCHAR(1000),
@UserID INT
)
AS
DECLARE @sql VARCHAR(1000)
SET @sql = 'INSERT INTO Signatures (UserID_FK, [Signature])
SELECT @UserID , BulkColumn
FROM OPENROWSET
(
Bulk '''+ @SignatureUri +''', SINGLE_BLOB
) AS [Signature]';
EXEC(@sql)
GO
I have change it to the following, but it now says 'Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.':
CREATE PROCEDURE Insert_Signatures_SP
(
@SignatureUri NVARCHAR(1000),
@UserID INT
)
AS
DECLARE @err INT
DECLARE @sql VARCHAR(1000)
SET @sql = 'INSERT INTO Signatures (UserID_FK, [Signature])
SELECT @UserID, BulkColumn
FROM OPENROWSET
(
Bulk '''+ @SignatureUri +''', SINGLE_BLOB
) AS [Signature]';
EXEC @err = sp_executesql @sql, N'@UserID INT', @UserID;
RETURN(@err);
GO
Trying to call it with:
EXEC Insert_Signatures_SP 'C:\Z_KB\SignTest.PNG', 3
1条答案
按热度按时间ui7jx7zq1#
@sql
must benvarchar(max)
.You should also correctly escape the URI using
QUOTENAME