DECLARE @CODE nvarchar(50) DECLARE image_cursor CURSOR FOR SELECT CODE FROM MyMast WHERE img IS NULL OPEN image_cursor; FETCH NEXT FROM image_cursor INTO @CODE; WHILE @@FETCH_STATUS = 1 BEGIN DECLARE @sql NVARCHAR(MAX) DECLARE @imagePath NVARCHAR(255) SET @imagePath = 'D:\images\'+ RTRIM(LTRIM('@CODE')) + '.jpg' SET @sql = 'UPDATE MyMast ' SET @sql = @sql + 'SET img = (SELECT BulkColumn FROM OPENROWSET( BULK ''' + @imagePath + ''', Single_Blob) AS img) ' SET @sql = @sql + 'WHERE CODE = ''' + (@CODE) +''';'; BEGIN TRY EXECUTE sp_executesql @sql END TRY BEGIN CATCH END CATCH FETCH NEXT FROM image_cursor INTO @CODE; END CLOSE image_cursor; DEALLOCATE image_cursor; SELECT CODE, img FROM MyMast WHERE img IS NOT NULL
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)