<script type=”text/javascript”><!–
google_ad_client = “pub-2910472071369479”;
//728×90, created 11/20/07
google_ad_slot = “7313632958”;
google_ad_width = 728;
google_ad_height = 90;
//–></script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js“>
</script>

src=”http://pagead2.googlesyndication.com/pagead/show_ads.js&#8221; mce_src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”&gt;

set nocount on
declare @sql nvarchar(2000)
declare @comp_code nvarchar(255), @pin nvarchar(255), @LoanType nvarchar(255), @datefrom nvarchar(255)
declare @temp_id int, @n int
declare @docNo nvarchar(20)

create table #temp
(
 _id int IDENTITY,
 Company nvarchar(255),
 PIN nvarchar(255),
 LoanType nvarchar(255),
 df nvarchar(255)
)

insert into #temp
select Company, PIN, LoanType, convert(varchar,convert(datetime, DateFrom, 103),112) as df
from sheet1 where LoanType in (’01’,’02’,’03’,’04’,’05’) and convert(datetime, DateTo, 103) >= getdate()
order by pin

set @n = 0

— loop —
declare cur cursor for
select _id from #temp
open cur
fetch next from cur into @temp_id   
 while @@fetch_status=0
 begin  
  set @n = @n + 1
  
  exec get_running_number @n, @docNo out
  
  select @comp_code=Company, @pin=PIN, @LoanType=LoanType, @datefrom=df from #temp where _id=@temp_id
  
  set @sql = ‘insert into welfare.WF2_TXN_CREMATION (Comp_Code,Pin,Doc_Date,Relat_Pers_Type, Doc_No) values ‘
  set @sql = @sql + ‘(”’ + @comp_code + ”’,”’+ @pin + ”’,”’ + @datefrom + ”’,”’
+ @LoanType + ”’,”’ + @docNo + ”’)’
  print (@sql)
  
  fetch next from cur into @temp_id  
 end
 
 print ‘– total record: ‘ + cast(@n as varchar)

close cur
deallocate cur

— drop table —
drop table #temp    

set nocount off