In my program I want to insert the images of students which are in a folder to the sql table according to id. Currently I used this querry.
declare EmployeCursor cursor fast_forward for
select num
from login
declare @sql nvarchar(4000)
declare @num nvarchar(50)
open EmployeCursor
while (1=1) begin
fetch next from EmployeCursor into @num
if @@FETCH_STATUS<>0 break
set @sql = N'UPDATE login
SET image =
(SELECT * FROM
OPENROWSET(BULK N''D:\img\' + cast(@num as nvarchar(50)) + N'.jpg'', SINGLE_BLOB) AS img)
WHERE num = ' + cast(@num as nvarchar(max))
exec(@sql)
end /* while */
close EmployeCursor
deallocate EmployeCursor
But its have problem.My image names are in the format 12-1.jpg and id in the format 12/1. so how can I add images? pls help

Khargesh RajputRank #616 · 3.9K reputationPosted Jan 3, 2015, 12:57 AM EST
e.g. save any file with name abc/.jpg not accept
vishnu suresh53 reputationPosted Jan 3, 2015, 4:10 AM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 4, 2015, 6:39 PM EST
vishnu suresh53 reputationPosted Jan 4, 2015, 7:32 PM EST
vishnu suresh53 reputationPosted Jan 4, 2015, 7:35 PM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 4, 2015, 7:46 PM EST
change it to 111-1
vishnu suresh53 reputationPosted Jan 4, 2015, 8:26 PM EST
sorry sir, I have a lot of collection of stud id, so it cannot be changed. is there any other coding available to insert 111-1.jpg to 111/1 id place,
eg: code:
replacing / with - for id
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 4, 2015, 10:34 PM EST
vishnu suresh53 reputationPosted Jan 4, 2015, 11:50 PM EST
vishnu suresh53 reputationPosted Jan 4, 2015, 11:53 PM EST
DECLARE image_cursors CURSOR FOR
SELECT CODE FROM MyMast WHERE img IS NULL
OPEN image_cursors;
FETCH NEXT FROM image_cursors
INTO @id;
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @sql VARCHAR(MAX)
DECLARE @imagePath VARCHAR(255)
SET @imagePath = 'D:\images' + RTRIM(LTRIM(@id)) + '.jpg'
SET @sql = 'UPDATE Mymast'
SET @sql = @sql + 'SET img = (SELECT BulkColumn FROM OPENROWSET( BULK ''' + @imagePath + ''', Single_Blob) AS Picture), SET PictureFileName = ' + @imagepath
SET @sql = @sql + 'WHERE id = ''' + @id + ''';'
BEGIN TRY
EXECUTE sp_executesql @sql
END TRY
BEGIN CATCH
END CATCH
FETCH NEXT FROM image_cursors
INTO @id;
END
CLOSE image_cursors;
DEALLOCATE image_cursors;
SELECT id, img FROM MyMast WHERE img IS NOT NULL
vishnu suresh53 reputationPosted Jan 4, 2015, 11:54 PM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 5, 2015, 1:20 AM EST
and 30 rows are updated becauses you may update with where cluase.
vishnu suresh53 reputationPosted Jan 5, 2015, 4:02 AM EST