MS Access (JET) SQL
This IDC code prevents duplicate records from being entered unless the LocationBarcode starts with an 'L' (case is ignored). Notice the use of 2 Select statements.
SQLStatement: + INSERT INTO [Item Transactions] ( + ItemID, ProductID, [InventoryItem Barcode], + PersonID, TransactionTypeID, [Transaction Date], + [Location Barcode] ) + SELECT Items.ItemID, Items.ProductID, Items.BarCode, + '%PersonID%' AS Person, 'loc' AS TransType, Now() AS TransDate, + '%LocationBarcode%' AS LocBarcode + FROM Items + WHERE Items.Barcode = '%ItemBarcode%' + AND Items.ItemID NOT IN + (SELECT ItemID + FROM [Item Transactions] + WHERE [Location Barcode] = '%LocationBarcode%' + AND Left('%LocationBarcode%', 1) <> 'L' + );(The constants - such as 'loc' - and computed values - Now() - are re-named so that they are available in the associated htx file.)
Normally, I use the MS Access query builder to write the SQL for me ... then I make simple mods (like adding the plus signs - +) by hand. However, notice that the MS Access query builder is not able to handle the
WHERE Field1 not in (select ...)construct.