Skip to content

Instantly share code, notes, and snippets.

@davidsheardown
Created November 2, 2021 09:49
Show Gist options
  • Save davidsheardown/0fab35746918f8aafd37113bbfa8924c to your computer and use it in GitHub Desktop.
Save davidsheardown/0fab35746918f8aafd37113bbfa8924c to your computer and use it in GitHub Desktop.
Add image to SQL encoded it Base64
CREATE PROCEDURE [dbo].[sp_add_image_to_SQL]
@ImageId int,
@ImageFilePath nvarchar(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sql_string nvarchar(max) =
N'UPDATE tbl_ext_product_images
SET [Image] = (SELECT BulkColumn
FROM Openrowset(Bulk ' + quotename(@ImageFilePath,nchar(39)) + ', Single_Blob) ImageData)
WHERE Id = @ImageId';
EXECUTE sp_executesql @sql_string, N'@ImageId bigint', @ImageId
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment