I need to write a stored procedure in SQL Server which can store Excel sheet into a database (maybe using blob) and then another procedure to retrieve the file back.
For inserting I tried
CREATE TABLE #ORStable (doclen BIGINT, doc VARBINARY(MAX))
INSERT INTO #ORStable
SELECT LEN(bulkcolumn), *
FROM OPENROWSET(BULK 'C:\Test\Test1.xlsx', SINGLE_BLOB) AS r
For retrieving:
DECLARE @SQLcommand NVARCHAR(4000)
SET @SQLcommand = 'bcp "SELECT doc FROM #ORStable " queryout "C:\test3.xlsx" -n -c '
EXEC xp_cmdshell @SQLcommand
The file must be stored completely with its formatting as well so when retrieved the exact file with formatting must be downloaded. This storing and retrieving must happen within SQL Server only and no application/code must be used.