The output ScreenshotI have a script, which loops through the SQL Server database table to determine the file type and subsequently rename the files on the network share to add the appropriate extension. Script given below:
DECLARE @UNC AS varchar(255), @Filetype AS varchar(255), @CMD AS VARCHAR(255)
declare @HPF_Test as cursor;
SET @HPF_Test = CURSOR FOR
select UNC, Filetype
from HPF_Test;
OPEN @HPF_Test;
Fetch NEXT from @HPF_Test into @UNC, @Filetype;
While @@fetch_status=0
begin
SELECT @CMD = 'REN ' + @UNC + ' '
+ RIGHT(@UNC, CHARINDEX('\', REVERSE(@UNC)) - 1)
+ case when @Filetype = 'TIF' THEN '.TIF' when @Filetype = 'TXT' THEN '.TXT' when @Filetype = 'XML' THEN '.XML' END
FROM HPF_Test
exec master..xp_cmdshell @CMD
Fetch next from @HPF_Test into @UNC, @Filetype
end
close @HPF_Test;
deallocate @HPF_Test;
Since there are approximately 92 million images that will need to be renamed it will take time for the whole process to run and complete. Therefore, I have a few questions that are listed below:
1) What can be added to the script to test whether all files were copied or not?
2) Someone suggested that we run the script in batches. How can I break it into batches?
Please help me in this regard. I am a novice in this regard.
Thanks!
Updates:
I have three files that I am testing this code on. So, when I run the above code I get three outputs, that are all NULL. However, when I try to capture the results in a table I get two records 1) The system cannot find the file specified & 2)NULL
I am using adding the script below to the original script to capture the results in a table.
CREATE TABLE #TEMP_test3(t nvarchar(255))
insert #TEMP_test3(t)
exec master..xp_cmdshell @CMD
select * from
#TEMP_test3
Could anyone please help me in this regard or at least tell me what am I doing wrong here?
Thanks!!!