I have this query below which I am getting certain columns from 1 database and I am then inserting them into another table in another database. I will then Delete the table I am copying from. At the moment it takes 5 minutes and 36 seconds to copy a bit over 5300 records. Is there any way I can improve the speed?
Declare @cursor cursor, @Firstname nchar(50), @MiddleInitial nchar(5),
@Surname nchar(50), @EmailAddress nchar(100), @DOB nchar(8), @Sex char(1), @altEmail nchar(100)
set @cursor = cursor for select Firstname, MiddleInitial, Surname, HomeEmailAddress,
DateOfBirth, Sex, WorkEmailAddress from cs_clients
open @cursor
fetch next from @cursor into @FirstName, @MiddleInitial, @Surname, @EmailAddress, @DOB, @Sex, @altEmail
while @@fetch_status = 0
begin
set nocount on
use hrwb_3_0
declare @Password nvarchar(100), @EncryptedText nvarchar(100)
exec L_Password_GetRandomPassword @Password output, @EncryptedText output
declare @userID nvarchar(100)
exec L_Password_GetRandomPassword @userID output, @EncryptedText output
set nocount off
set @EmailAddress = isnull(@EmailAddress, @altEmail)
insert into A_User values
('CS', 'CLUBSAIL', rtrim(@userID), rtrim(@Password), rtrim(@Surname), rtrim(@FirstName), rtrim(@MiddleInitial), 15, 'NA', 'NA', '', rtrim(@EmailAddress), rtrim(@DOB), 1, 0, 1, 0, '', rtrim(@Sex), '')
fetch next from @cursor into @FirstName, @MiddleInitial, @Surname, @EmailAddress, @DOB, @Sex, @altEmail
end