query: #title: Trailing check digit in a GTIN must be correct
  # Complex constraint from [[Property talk:P3962]]
  # [https://www.gs1.org/services/how-calculate-check-digit-manually Algorithm for checking whether the trailing check digit is correct]
  SELECT ?item WHERE { ?item wdt:P3962 ?GTIN. BIND(CONCAT("000000", ?GTIN) AS ?extended). BIND(SUBSTR(?extended, STRLEN(?extended) - 13, 14) AS ?padded). BIND(xsd:decimal(SUBSTR(?padded, 1, 1)) AS ?digit1). BIND(xsd:decimal(SUBSTR(?padded, 2, 1)) AS ?digit2). BIND(xsd:decimal(SUBSTR(?padded, 3, 1)) AS ?digit3). BIND(xsd:decimal(SUBSTR(?padded, 4, 1)) AS ?digit4). BIND(xsd:decimal(SUBSTR(?padded, 5, 1)) AS ?digit5). BIND(xsd:decimal(SUBSTR(?padded, 6, 1)) AS ?digit6). BIND(xsd:decimal(SUBSTR(?padded, 7, 1)) AS ?digit7). BIND(xsd:decimal(SUBSTR(?padded, 8, 1)) AS ?digit8). BIND(xsd:decimal(SUBSTR(?padded, 9, 1)) AS ?digit9). BIND(xsd:decimal(SUBSTR(?padded, 10, 1)) AS ?digit10). BIND(xsd:decimal(SUBSTR(?padded, 11, 1)) AS ?digit11). BIND(xsd:decimal(SUBSTR(?padded, 12, 1)) AS ?digit12). BIND(xsd:decimal(SUBSTR(?padded, 13, 1)) AS ?digit13). BIND(xsd:decimal(SUBSTR(?padded, 14, 1)) AS ?digit14). BIND(?digit1 * 3 + ?digit2 + ?digit3 * 3 + ?digit4 + ?digit5 * 3 + ?digit6 + ?digit7 * 3 + ?digit8 + ?digit9 * 3 + ?digit10 + ?digit11 * 3 + ?digit12 + ?digit13 * 3 AS ?sum). BIND(xsd:decimal(SUBSTR(xsd:string(?sum), STRLEN(xsd:string(?sum)), 1)) AS ?lastsumdigit). BIND(IF(?lastsumdigit = 0, 0, 10 - ?lastsumdigit) AS ?checkdigit). FILTER(?digit14 != ?checkdigit) } LIMIT 1000