I have an SQL statement that has several ANDs in the WHERE cluse and I want to know if I can have an IF THEN ELSE statement under the WHERE clause to determine what AND will execute.
Three parameters will be passed to this query
WHERE tlv.active = 1
AND tli.active = 1
AND t.endWorkShiftId IS NOT NULL
AND t.voidTypeId IS NULL
AND tlv.customerId = 1
AND tlv.locationId = 1
AND tlv.dockId = 3
IF ( :referenceId IS NULL ) {
AND tlv.vendorCldcId = :vendCldId
AND tlv.vendorId = :vendId
}
ELSE {
AND vru.refId = :referenceId
}