V
V
Vladislav Sofienko2017-03-17 21:42:11
SQL
Vladislav Sofienko, 2017-03-17 21:42:11

OpenRowSet BULK TSQL How to load files into the database?

Hello. I'm trying to load pictures into a table through a loop using BULK, but I can't add a variable, a field, or even join rows in BULK.
How to solve this situation?

WHILE @i <= (SELECT Count(*) FROM [dbo].[Charity])
BEGIN
  UPDATE [dbo].[Charity]
  SET [CharityLogoImg] = (SELECT * FROM OpenRowSet (BULK N'H:\Charity\' + CharityLogo, SINGLE_BLOB) As Файл)
  WHERE [CharityId] = @i

  SET @i = @i + 1
END
GO

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2017-03-17
@sofvlad

Well, firstly, set field = (select * ...) and will not work, because "select *" means returning a lot of columns ...
therefore, at least set поле = (select конкретное_поле from ...)
secondly, the loop in this construction is not needed
, you can use

update t2
set t2.field=t1.field
from t1 
join t2 on t2.id=t1.id
where ...

https://msdn.microsoft.com/en-us/library/ms177523.aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question