The follow code is running across 1300+ records in a table, and may have 10-20 records in it. But it is taking 4 and a half minutes. Other stored procedures take like 10 seconds and have way more records (like 200K), and use the same structure.
CREATE PROC dbo.kv_updt_RECIP_AUTH_ONWAY2IBM AS
DECLARE @fundnum varchar(2)
DECLARE @scandate datetime
DECLARE @batchnum varchar(25)
DECLARE @ssn varchar(9)
DECLARE @local varchar(4)
DECLARE @sigdate datetime
DECLARE @annuity_doc_type varchar(50)
DECLARE @annuity_output_type varchar(3)
DECLARE @pension_doc_type varchar(50)
DECLARE @pension_output_type varchar(3)
DECLARE @health_doc_type varchar(50)
DECLARE @health_output_type varchar(3)
DECLARE @wpasid varchar(7)
DECLARE @firstname varchar(15)
DECLARE @lastname varchar(30)
DECLARE the_cursor CURSOR for
SELECT fundnum, scan_date, batchnum, ssn, local, sigdate, annuity_doc_type, annuity_output_type, pension_doc_type, pension_output_type, health_doc_type, health_output_type, wpasid, first_name, last_name
FROM [RECIP Authorization Forms].[dbo].[BACKfromIBM]
WHERE Last_name IS NOT NULL
OPEN the_cursor
FETCH NEXT FROM the_cursor
into @fundnum, @scandate, @batchnum, @ssn, @local, @sigdate, @annuity_doc_type, @annuity_output_type, @pension_doc_type, @pension_output_type, @health_doc_type,
@health_output_type, @wpasid, @firstname, @lastname
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE [RECIP Authorization Forms].[DBO].[ONWAY2IBM]
SET First_Name = @firstname,
Last_Name = @lastname,
Wpasid = @wpasid
WHERE Fundnum = @fundnum
AND Scan_Date = @scandate
AND SSN = @ssn
and not SSN = '999999999'
and not SSN = '000000000'
UPDATE [RECIP Authorization Forms].[DBO].[ONWAY2IBM]
SET First_Name = @firstname,
Last_Name = @lastname,
SSN = @ssn
WHERE Fundnum = @fundnum
AND Scan_Date = @scandate
AND Wpasid = @wpasid
and not WPASID = '9999999'
and not WPASID = '0000000'
FETCH NEXT FROM the_cursor into @fundnum, @scandate, @batchnum, @ssn, @local, @sigdate, @annuity_doc_type, @annuity_output_type, @pension_doc_type, @pension_output_type, @health_doc_type, @health_output_type, @wpasid, @firstname, @lastname
END
CLOSE the_cursor
DEALLOCATE the_cursor
GO
Any advice ya'll have would be much appreciated. I am a Senior Mainframe programmer, who has been maintaining the SQL DB's (on the PC side) on top of it. So I am not formally trained in the PC side. I have gotten things done through the school of hard knocks, and advice on this forum when it comes to SQL.
CREATE PROC dbo.kv_updt_RECIP_AUTH_ONWAY2IBM AS
DECLARE @fundnum varchar(2)
DECLARE @scandate datetime
DECLARE @batchnum varchar(25)
DECLARE @ssn varchar(9)
DECLARE @local varchar(4)
DECLARE @sigdate datetime
DECLARE @annuity_doc_type varchar(50)
DECLARE @annuity_output_type varchar(3)
DECLARE @pension_doc_type varchar(50)
DECLARE @pension_output_type varchar(3)
DECLARE @health_doc_type varchar(50)
DECLARE @health_output_type varchar(3)
DECLARE @wpasid varchar(7)
DECLARE @firstname varchar(15)
DECLARE @lastname varchar(30)
DECLARE the_cursor CURSOR for
SELECT fundnum, scan_date, batchnum, ssn, local, sigdate, annuity_doc_type, annuity_output_type, pension_doc_type, pension_output_type, health_doc_type, health_output_type, wpasid, first_name, last_name
FROM [RECIP Authorization Forms].[dbo].[BACKfromIBM]
WHERE Last_name IS NOT NULL
OPEN the_cursor
FETCH NEXT FROM the_cursor
into @fundnum, @scandate, @batchnum, @ssn, @local, @sigdate, @annuity_doc_type, @annuity_output_type, @pension_doc_type, @pension_output_type, @health_doc_type,
@health_output_type, @wpasid, @firstname, @lastname
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE [RECIP Authorization Forms].[DBO].[ONWAY2IBM]
SET First_Name = @firstname,
Last_Name = @lastname,
Wpasid = @wpasid
WHERE Fundnum = @fundnum
AND Scan_Date = @scandate
AND SSN = @ssn
and not SSN = '999999999'
and not SSN = '000000000'
UPDATE [RECIP Authorization Forms].[DBO].[ONWAY2IBM]
SET First_Name = @firstname,
Last_Name = @lastname,
SSN = @ssn
WHERE Fundnum = @fundnum
AND Scan_Date = @scandate
AND Wpasid = @wpasid
and not WPASID = '9999999'
and not WPASID = '0000000'
FETCH NEXT FROM the_cursor into @fundnum, @scandate, @batchnum, @ssn, @local, @sigdate, @annuity_doc_type, @annuity_output_type, @pension_doc_type, @pension_output_type, @health_doc_type, @health_output_type, @wpasid, @firstname, @lastname
END
CLOSE the_cursor
DEALLOCATE the_cursor
GO
Any advice ya'll have would be much appreciated. I am a Senior Mainframe programmer, who has been maintaining the SQL DB's (on the PC side) on top of it. So I am not formally trained in the PC side. I have gotten things done through the school of hard knocks, and advice on this forum when it comes to SQL.