These guidelines apply to both diagnostic and procedure data.

After importing the received data into WampServer, you can run the following SQL queries to detect any data issues. Steps 1, 3, 4 and 5 are mandatory, while step 2 is optional and depends on the results of step 1.

Step 1: Use the query below to check minimum and maximum characters of the code

-- Both datasets return min and max code length and display percentage

SELECT 

    MIN(LENGTH(code)) AS min_length,

    MAX(LENGTH(code)) AS max_length,

    -- Percentage of minimum length relative to maximum length

    ROUND(

        (MIN(LENGTH(code)) / MAX(LENGTH(code))) * 100,

        2

    ) AS min_length_percentage

FROM table_name; -- Replace with your table name

Step 2: The following provides additional details to step 1 in cases of an abnormal result.

-- Both datasets return the longest code value(s)

SELECT 

    code,

    CHAR_LENGTH(code) AS length

FROM 

    your_table_name -- Replace with your table name

WHERE 

    CHAR_LENGTH(code) = (

        SELECT MAX(CHAR_LENGTH(code)) 

        FROM your_table_name -- Replace with your table name

    );

Step 3: For diagnostics, find and list any missing prefix letters.

-- Diagnostics count distinct first letters between A and Q and lists missed

WITH RECURSIVE alphabet AS ( 

    SELECT 'A' AS letter

    UNION ALL

    SELECT CHAR(ASCII(letter) + 1)

    FROM alphabet

    WHERE letter < 'Q'   -- Stop at Q (inclusive range A–Q)

),

used_letters AS (

    SELECT DISTINCT UPPER(LEFT(code, 1)) AS letter

    FROM your_table_name -- Replace with your table name

    WHERE UPPER(LEFT(code, 1)) BETWEEN 'A' AND 'Q'

),

missing_letters AS (

    SELECT a.letter

    FROM alphabet a

    LEFT JOIN used_letters u 

        ON a.letter = u.letter

    WHERE u.letter IS NULL

)

SELECT 

    (SELECT COUNT(*) FROM used_letters) AS letters_present,

    (SELECT COUNT(*) FROM missing_letters) AS letters_missing,

    (SELECT GROUP_CONCAT(letter ORDER BY letter SEPARATOR ', ')

        FROM missing_letters) AS missing_letter_list;

Step 4: For procedures, find and list any missing prefix letters.

-- Procedures count distinct first letters between A and Z and lists missed

WITH RECURSIVE alphabet AS ( 

    SELECT 'A' AS letter

    UNION ALL

    SELECT CHAR(ASCII(letter) + 1)

    FROM alphabet

    WHERE letter < 'Z'

),

used_letters AS (

    SELECT DISTINCT UPPER(LEFT(code, 1)) AS letter

    FROM your_table_name -- Replace with your table name

    WHERE UPPER(LEFT(code, 1)) BETWEEN 'A' AND 'Z'

),

missing_letters AS (

    SELECT a.letter

    FROM alphabet a

    LEFT JOIN used_letters u 

        ON a.letter = u.letter

    WHERE u.letter IS NULL

)

SELECT 

    (SELECT COUNT(*) FROM used_letters) AS letters_present,

    (SELECT COUNT(*) FROM missing_letters) AS letters_missing,

    (SELECT GROUP_CONCAT(letter ORDER BY letter SEPARATOR ', ')

        FROM missing_letters) AS missing_letter_list;

Step 5: Check the case numbers

Once you have completed the above steps, please examine the case number column to ensure the values are logical and consistent.



Topic last reviewed: 18/02/26