How to insert audio into SQL Server
Insert Into [dbo].[Letterland] ([letter],[letterImage])
Select 'a', BulkColumn,
From Openrowset (bulk 'H:\Data\D\ll-image\annie.png', Single_blob) as img
Insert Into [dbo].[Letterland] ([letterDescAudio])
Select 'a', BulkColumn, BulkColumn
From Openrowset (bulk 'H:\Data\D\11-image\aa.wav' Single_blob) as img
Insert Into [dbo].[Letterland] ([letterSound])
Select 'a', BulkColumn, BulkColumn
From Openrowset (bulk 'H:\Data\D\ll-image\a.wav', Single_blob) as img
This is what I have tried but I know it is not correct. I am trying to insert data as one line.
[dbo].[Letterland] ([Letter], [letterImage], [letterDescAudio], [letterSound])
+3
user3466153
source
to share
2 answers
Well, you need to load three blobs into variables first, and then do one INSERT
to insert them all into your table - something like this:
-- declare a VARBINARY(MAX) variable to hold the "image"
DECLARE @Image VARBINARY(MAX)
-- load the "image"
SELECT @Image = BulkColumn,
FROM Openrowset (bulk 'H:\Data\D\ll-image\annie.png', Single_blob) as img
-- declare a VARBINARY(MAX) variable to hold the "Desc Audio" and load it
DECLARE @DescAudio VARBINARY(MAX)
SELECT @DescAudio = BulkColumn
FROM Openrowset (bulk 'H:\Data\D\11-image\aa.wav' Single_blob) as img
-- declare a VARBINARY(MAX) variable to hold the "Sound" and load it
DECLARE @Sound VARBINARY(MAX)
SELECT @Sound = BulkColumn
FROM Openrowset (bulk 'H:\Data\D\ll-image\a.wav', Single_blob) as img
-- now do the INSERT with all bits ready to go
INSERT INTO dbo.Letterland (letter, letterImage, letterDescAudio, letterSound)
VALUES ('a', @Image, @DescAudio, @Sound)
+1
source to share