On user input form there are 4 rows and 4 columns. Each row and column has the same input.
Col 1 is "Begin Date"; Col 2 is "End Date"; Col 3 is "Type Hours" and this is option list with 4 selections - 1. Comp; 2. Credit; 3. OT; and, 4. Rel Comp.
Col 4 is "Number of Hours."
User selections may or may not include Rel Comp. But, if Rel Comp selected then user must also enter two more dates in two other input boxes - Rel Comp Begin Date and Rel Comp End Date.
OK - here's an example. A user selects the following:
Row 1 - Begin and End dates; Type Hours = Credit; # Hours = 2
Row 2 - Begin and End dates; Type Hours = Comp; # Hours = 1
Row 3 - Begin and End dates; Type Hours = Rel Comp; # Hours = 4
Row 4 - Begin and End dates; Type Hours = OT; # Hours = 2.
Rel Comp Begin and End Dates are needed only for Row 3 entry. However, in my database those dates are being posted to the other three selections. I want those other three selections to show NULL for Rel Comp Begin and End Dates and for the Rel Comp entry the Rel Comp Begin and End Dates should show the user's entered dates.
Hope this makes sense. Anyway, I need an IF Statement to accomplish this and I do not know how to do this. I'm guessing that I need the IF Statement before the INSERT statement but how do I word it?
Any suggestions?
The code I have is
Code:
<cfloop from="1" to="4" index="i" step="1">
<cfif IsDate(evaluate("Form.StartDate" & i))>
<cfquery name="qInsertRequest" datasource="RAWH">
Insert into RAWH
(EmpPIN,
Empname,
dateRequested,
startdate,
stopdate,
TypeHrs,
NoOfHours,
projects,
justification,
RCbeginDate,
RCendDate,
RCLvSlip,
reqDecision,
denialReason)
VALUES (
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.EmpPIN#" null="#IIF(Len(Trim(Form.EmpPIN)), DE('no'), DE('yes'))#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.EmpName#" null="#IIF(Len(Trim(Form.EmpName)), DE('no'), DE('yes'))#" />,
getdate(),
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Evaluate("Form.startdate" & i)#" />,
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Evaluate("Form.stopdate" & i)#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Evaluate("Form.TypeHrs" & i)#" />,
<cfqueryparam cfsqltype="cf_sql_decimal" scale="2" value="#Evaluate("Form.NoOfHours" & i)#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.projects#" null="#IIF(Len(Trim(Form.projects)), DE('no'), DE('yes'))#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.justification#" null="#IIF(Len(Trim(Form.justification)), DE('no'), DE('yes'))#" />,
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Form.RCbeginDate#" null="#IIF(Len(Trim(Form.RCbeginDate)), DE('no'), DE('yes'))#" />,
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Form.RCendDate#" null="#IIF(Len(Trim(Form.RCendDate)), DE('no'), DE('yes'))#" />,
<cfqueryparam cfsqltype="cf_sql_char" value="#Form.RCLvSlip#" null="#IIF(Len(Trim(Form.RCLvSlip)), DE('no'), DE('yes'))#" />,
null,
null)
</cfquery>
</cfif>
</cfloop>
Thanks,
John