Skip to content
Partner Developer Portal

Definition

The Variation Scottishethnicity model holds Scottish ethnicity coding entries, including descriptions, group codes and national codes. Each entry records a code identifier and a current-status value, together with the MKB version and EMIS organisation value recorded for that coding entry.

_deleted indicates whether the record has been deleted in the source system.

variation.scottishethnicity with dbo.codelookup details

Section titled “variation.scottishethnicity with dbo.codelookup details”

Return records alongside descriptive values from the related dbo.codelookup record.

:::caution[Unverified join] This join is inferred from matching column names and is not part of the documented relationships. Check the results before relying on it. :::

SELECT
m."_primary_key",
m."codeid",
p1."term" AS "codelookup_term"
FROM variation.scottishethnicity AS m
LEFT JOIN dbo.codelookup AS p1
ON p1."emiscodeid" = m."codeid"
AND p1."organisation" = m."organisation";

Count variation.scottishethnicity records for each dbo.codelookup value, joined on codeid.

:::caution[Unverified join] This join is inferred from matching column names and is not part of the documented relationships. Check the results before relying on it. :::

SELECT
p."term" AS "codelookup_term",
COUNT(*) AS row_count
FROM variation.scottishethnicity AS m
INNER JOIN dbo.codelookup AS p
ON p."emiscodeid" = m."codeid"
AND p."organisation" = m."organisation"
GROUP BY p."term"
ORDER BY row_count DESC;

Find variation.scottishethnicity records whose codeid has no matching dbo.codelookup record.

:::caution[Unverified join] This join is inferred from matching column names and is not part of the documented relationships. Check the results before relying on it. :::

SELECT
COUNT(*) AS unmatched_count
FROM variation.scottishethnicity AS m
LEFT JOIN dbo.codelookup AS p
ON p."emiscodeid" = m."codeid"
AND p."organisation" = m."organisation"
WHERE m."codeid" IS NOT NULL
AND p."emiscodeid" IS NULL;