Skip to content

A SQL COUNT query used to check for duplicate values on a Custom Page returns the correct number when run directly in a SQL query tool, but always returns 0 when embedded as the same-looking query on the custom page itself, comparing what look like the same values.

Answer

Check whether the fields you're comparing against (e.g. in the WHERE clause) are Persistent Custom Fields of type Reference — if so, the underlying table (_CFT/_CLT) actually stores the referenced record's ROWKEY (a GUID), not the human-readable key value you're used to seeing. The corresponding view (_CFV/_CLV) resolves that ROWKEY into the friendly value you see on screen, exposing it as two separate columns: a plain column (e.g. CF$_SUPPLIER) with the friendly value, and a _DB-suffixed column (e.g. CF$_SUPPLIER_DB) with the raw ROWKEY. If your custom page's query runs against the table (or against bind parameters that ultimately come from the table), comparing to the friendly value in your WHERE clause will never match, since the table itself only holds the ROWKEY — compare against the _DB column instead (or select from the _CFV/_CLV view if you need the friendly value directly).

← Browse Developer Studio, deployment, and upgrades questions