i have 2 files ...one for entering values in input box (eg: value.asp) and another for saving the values (eg: save.asp)
after submitting value.asp ,i pass values to save.asp....
what i want is while i execute the for loop if there is NO records it should insert the new value 'and if there is record it should run update query...
but now what is happening is, if there is no record it will insert all the new record ,after that, it goes to else condition loop and run update query also.
ie.instead of executing only the insert query, it will execute update query also..
<body>
<form name="confstaffleaveSave" method="post">
<input type="text" name ="emp_num" value ="<%=login%>">
<%
if true then
session.Contents("secondtime")=login
dim TodaysDate
sql3="select to_char(sysdate,'DD-Mon-YY') from dual"
set rs1=conn2.execute(sql3)
TodaysDate=rs1(0).value
' Response.Write ("<br>" + TodaysDate)
dim getReason,getLeaveCode,getHolidayCode,getEmpNum,ge tLeaveName,getApplDate,getJoinDate1,leavearray,get holiday
dim getLeaveYear_From,getLeaveYear_To,getLeave_Code,ge tHOLI_CODE,getValid_to_date,getOpening_Balance,get Current_Credit,getNotHoli,Not_holi_count
dim getLeave_Taken,getAdded_to_AL,getActive,getappcode ,prev,codeva,curva,curvalue,prevvalue,checksql2,ge tLastHoli,last_holi_count
session.Contents("loginempno")=loginuser
'*************************PREVIOUS YEAR LEAVE DETAILS ***********************
getEmpnum=trim(Request.Form("emplist"))
getappcode=Request.Form("appcode")
getLeaveYear_From ="01-Jul-06"
getLeaveYear_To ="30-Jun-07"
'**********************ENTERING LEAVE DETAILS*******************
for i = 1 to 4
prev = "prev" & i ' input box name
codeva = "code" & i ' input box name
curva= "cur" & i ' input box name curvalue=trim(Request.Form(curva))'*****CURRENT leave year credit
prevvalue= trim(Request.Form(prev))'**** leave taken last year
code=trim(Request.Form(codeva)) '*****leave code
if prevvalue= "" then
prevvalue = 0
end if
if curvalue= "" then
curvalue = 0
end if
Response.Write ("<br />Loop---"& i &"<br />")
'CHECKING IF ANY OF THE LEAVE SELECTED EXISTS FOR THAT PARTICULAR EMPLOYEE
checksql2="select * from LeaveOpeningBalance where EMPNO = '"& getEmpNum &"' and " & _
"leave_code='"& code &"' and record_active='Y'"
set rs7=conn1.execute(checksql2)
if rs7.eof=true then '***********NO RECORDS
'*************INSERTING NEW LEAVE DATA **********************
sql_insert1 = "insert into LeaveOpeningBalance(empno,LeaveYear_From,LeaveYear _To," & _
" Leave_Code,Valid_to_date,Opening_Balance,Current_C redit,Leave_Taken,Added_to_AL, " & _
" Active,CREATED_ON,CREATED_BY,LAST_MODIFYON,LAST_MO DIFYBY,RECORD_ACTIVE ) values " & _
" ('"& getEmpNum &"',to_date('"& getLeaveYear_From &"','DD-Mon-YY'), " & _
" to_date('"& getLeaveYear_To &"','DD-Mon-YY'),'"& code &"'," & _
" '','"& prevvalue &"','"& curvalue &"', " & _
" '0','N','Y','"& TodaysDate &"','"& loginuser &"','"& TodaysDate &"','"& loginuser &"','Y')"
Response.Write ("<br /> INSERTING DATA --" & sql_insert1)
conn1.execute(sql_insert1)
else ' RECORD EXISTS
'*************UPDATING DATA**********************
sqlUP1 = "update LeaveOpeningBalance set OPENING_BALANCE='"& prevvalue &"', " & _
" LAST_MODIFYON='"& TodaysDate &"',LAST_MODIFYBY='"& loginuser &"' " & _
" where EMPNO = '"& getEmpNum &"' and Leave_CODE='"& code &"' " & _
" and LeaveYear_From =to_date('"& getLeaveYear_From &"','DD-Mon-YY') " & _
" and LeaveYear_To=to_date('"& getLeaveYear_To &"','DD-Mon-YY') and record_Active='Y' "
conn1.execute(sqlUP1)
Response.Write ("<br /> UPDATING DATA --" & sqlUP1)
end if
next
conn1.close
conn2.close
%>
<table width="75%" border="0" align="center" cellspacing="0" bordercolor="#336699">
<tr>
<td><div align="center">Thank You for submitting your leave details of previous year and current year..</div></td>
</tr>
<Tr><td align="center"><br><input type="button" value="Back" id=button1 name=ContBtn onClick="javascript:gotoMain();"></td></tr>
</table>
</form>
</body>