开发者

Blob combine in SQL Server 2008

开发者 https://www.devze.com 2023-03-12 11:49 出处:网络
I have a table that has the following schema: Create table TempMedia id int Primary key, mediaidint, FileData varbinary(max)

I have a table that has the following schema:

Create table TempMedia

id int Primary key,
mediaid  int,
FileData varbinary(max)

This table has parts of the full file (we use a silverlight control to chunk the data to the web server)

We store the full file in another table:

create table Media
id int primary key,
FileData varbinary(max)

Is there are way to perform an insert into the Media table that concatenates the file parts completely in SQL, so we end up with the full file in the Media table? At the moment we combine these file parts by selecting the data from the TempMedia table and combining it on the web server a开发者_开发知识库nd then inserting back to the Media table. Ideally we like to do this only on the SQL Server.


This should get the concatenated binary which you can then insert into your table.

DECLARE @bin varbinary(max)
SELECT @bin=CASE WHEN @bin is null THEN FileData ELSE @bin + FileData END
FROM TempMedia
WHERE MediaId = @mediaId
ORDER BY id -- make sure this is sequential
0

精彩评论

暂无评论...
验证码 换一张
取 消