<%
dim ccOne,ccTwo,ccThree,divideBy,percentRate
ccOne = false
ccTwo = false
ccThree = false
divideby = 0
percentRate = 0
'NOTE the divideBy variable tells us how many have been entered
'therefore how much to divide 100% by
if trim(request.form("costCode1")) <> "" then
'costCode1 has been entered
ccOne = true
divideBy = divideBy + 1
elseif trim(request.form("costCode2")) <> "" then
'costCode2 has been entered
ccTwo = true
divideBy = divideBy + 1
elseif trim(request.form("costCode3")) <> "" then
'costCode3 has been entered
ccThree = true
divideBy = divideBy + 1
end if
divideBy = 3
'cant divide by 0 so check is greater than zero
if cint(divideBy) > 0 then
percentRate = (100 / cint(divideBy))
end if
'Your sql statement
sql = "INSERT INTO [tbleName] ( someIntField "
if ccOne = true then sql = sql & " ,costCode1, Allocation2" end if
if ccTwo = true then sql = sql & " ,costCode2, Allocation2" end if
if ccThree = true then sql = sql & " ,costCode3, Allocation3" end if
'use cInt here to truncate the .333 from percentRate if value has been divided by three
'NOTE: I have assumed your allocation fields are intergers - they should be for future stats etc
sql = sql & ") VALUES (" & someIntValue & ""
if ccOne = true then sql = sql & " ,'" & trim(request.form("costCode1")) & "'," & cint(percentRate) end if
if ccTwo = true then sql = sql & " ,'" & trim(request.form("costCode1")) & "'," & cint(percentRate) end if
if ccThree = true then sql = sql & " ,'" & trim(request.form("costCode1")) & "'," & cint(percentRate) end if
sql = sql & ");"
%>
Wind is your friend
Matt
|