ShawnJClapper
Programmer
I'm getting sql timeout errors with this code, so I'm wondering if someone could help me make it smaller. I was wondering if there was a way to grab the @@Identity while inserting records so I didn't have to do the third statement which searches the key column for a unique id. Here is what I'm looking at:
The tblFISData is a temporary table that the data is loaded into and then sorted to the appropriate tables. The first two inserts work fine, however I'm running into problems on the third insert and maybe because it's such a large query. What happens is if I start with a fresh tblHomes date (nothing in it), the script runs fine, however if I try to run this a second time after all of the data is loaded into tblHomes I recieve an sql timeout error. Any suggestions?
Code:
currentSelect="select distinct sales_price, sales_date from tblFISData WHERE not exists (select salePrice, saleDate from tblsales where tblFISData.sales_price=tblsales.salePrice and tblFISData.sales_date=tblsales.saleDate)"
insertCommand.CommandText = "Insert into tblsales (salePrice,saleDate) "¤tSelect
insertCommand.Execute()
currentSelect="select distinct lender, rate_type,loan_type,mortgage_years,transaction_type,mortgage_amount from tblFISData WHERE not exists (select * from tblLoans where tblFISData.lender=tblLoans.lender and tblFISData.rate_type=tblLoans.rateType and tblFISData.loan_type=tblLoans.loanType and tblFISData.mortgage_years=tblLoans.mortLength and tblFISData.transaction_type=tblLoans.transType and tblFISData.mortgage_amount=tblLoans.mortAmount )"
insertCommand.CommandText = "Insert into tblLoans (lender,rateType,loanType,mortLength,transType,mortAmount) "¤tSelect
insertCommand.Execute()
currentSelect="select tblLoans.loanID, tblsales.saleID from tblLoans,tblsales,tblFISData WHERE tblFISData.lender=tblLoans.lender and tblFISData.rate_type=tblLoans.rateType and tblFISData.loan_type=tblLoans.loanType and tblFISData.mortgage_years=tblLoans.mortLength and tblFISData.transaction_type=tblLoans.transType and tblFISData.mortgage_amount=tblLoans.mortAmount and tblFISData.sales_price=tblsales.salePrice and tblFISData.sales_date=tblsales.saleDate and not exists (select * from tblHomes where tblLoans.loanID=tblHomes.loanID and tblsales.saleID=tblHomes.saleID)"
insertCommand.CommandText = "Insert into tblHomes (loanID,saleID) "¤tSelect
insertCommand.Execute()
The tblFISData is a temporary table that the data is loaded into and then sorted to the appropriate tables. The first two inserts work fine, however I'm running into problems on the third insert and maybe because it's such a large query. What happens is if I start with a fresh tblHomes date (nothing in it), the script runs fine, however if I try to run this a second time after all of the data is loaded into tblHomes I recieve an sql timeout error. Any suggestions?