Web design and hosting, database, cloud and social media solutions that deliver business results
  • Business Solutions
    • Robotic Process Automation
    • Bespoke Software
    • Database Services
      • Data Integration
      • Datawarehouse Services
      • Power BI
      • Server Upgrade and DBA Services
    • Web Services
      • Logo Design
      • Payment Gateways
      • Web Localisation and Translation
      • Web Site Optimisation
      • Web Site Security
      • Technical Tools
    • Cloud Services
      • Amazon Web Services
      • Google Cloud Services
      • Microsoft Azure
    • Microsoft 365
      • Enabling the Multi Factor Authentication Application
      • Office 365 DNS Settings Generator
    • IT Hardware
    • Social Media Services
  • Academy
    • Our Test Environment
    • Learning Databases
      • The Basics
      • Get Open Query
      • SQL Server Data
      • SQL Server Maintenance
      • Using SQL Server Dates
      • Using SQL Server Functions
      • Using SQL Server Pivot-Unpivot
      • Technical Tools
    • Learning Web Design
      • Building Ousia Content Management System
      • Using ASP-NET
      • Using CSS
      • Using JavaScript
    • Learning Cloud and IT Services
      • Task Scheduler Error 2147943645
      • Blocking Blank Senders
      • Requesting SSL and Generation of PFX file in OpenSSL Simple Steps
    • Using Social Media
      • Asking for a Google Review
      • Changing a Facebook account from personal to business
      • Choosing where to focus Social Media effort
      • Social Media Image Sizes
      • Using Meta Data to set Social Media Images
  • About
    • Blog
      • Building an entry level gaming machine
      • Google Core Update Jan 2020
      • Hot Chilli Internet Closure
      • How To Choose Content For Your Website Adverts Leaflets
      • Preventing Online Scam
      • Skimmers of the gig economy
      • The most annoying things about websites on the Internet
      • Top 5 websites for free Vector Graphics
    • Careers
      • Translator English-Japanese
      • Translator English-Portuguese
      • Translator English-Spanish
      • Translator English-Turkish
    • Portfolio
    • Regulatory
    • Team
      • Chester Copperpot
      • Gavin Clayton
      • Sai Gangu
      • Suneel Kumar
      • Surya Mukkamala
čeština (CS)Deutsch (DE)English (EN-US)English (EN-GB)Español (ES)Français (FR)हिंदी (HI)italiano (IT)日本語 (JA)polski (PL)Português (PT)русский (RU)Türk (TR)中国的 (ZH)

Check SEDOL format with an SQL Function

Create a function to Check the SEDOL number format in SQL Server

Context

Using Financial Data

This code was created as part of an import routine to cleanse data coming in from external sources, where there were all sorts of characters that shouldn't have been there.

This one checks the format of an SEDOL. This is expanded SQL code using the documentation on the Wikipedia article on the link.

This is part of three linked articles which will check ISIN, SEDOL and CUSIP identifiers.

SQL

ALTER FUNCTION CheckSEDOL(@SEDOL NVARCHAR(20))RETURNS INT AS BEGINDECLARE @Check INTIF RIGHT(@SEDOL,1) NOT BETWEEN '0' AND '9' BEGINSET @Check=-1RETURN @CheckENDIF PATINDEX('%[^0-Z]%',@SEDOL)>0 BEGINSET @Check=-3RETURN @CheckEND
DECLARE @Sum INT=0,@Letter INT=1,@Char VARCHAR(1)WHILE @LetterBEGINSET @Char=SUBSTRING(@SEDOL,@Letter,1)SET @Sum=@Sum+((SELECT (CASE WHEN @Char BETWEEN '0' AND '9' THEN @Char ELSE ASCII(UPPER(@Char))-55 END))*(CASE @Letter WHEN 1 THEN 1 WHEN 2 THEN 3 WHEN 3 THEN 1 WHEN 4 THEN 7 WHEN 5 THEN 3 WHEN 6 THEN 9 WHEN 7 THEN 1 ELSE 0 END))SET @Letter=@Letter+1ENDSET @Sum=(10 - @Sum%10)% 10
IF LEN(@SEDOL)<>7 BEGINSET @Check=-4RETURN @CheckEND
IF RIGHT(@SEDOL,1) BETWEEN '0' AND '9' BEGINSET @Check =(CASE WHEN RIGHT(@SEDOL,1)=@Sum THEN 1 ELSE 0 END)ENDRETURN @CheckEND

Warning!

This will only check the format of the SEDOL, not whether it actually exists.

Further Reading

Check an ISIN
more: Check ISIN format with an SQL Function
Check a CUSIP
more: Check CUSIP format with an SQL Function

Was this helpful?

Please note, this commenting system is still in final testing.

Author

Copyright Claytabase Ltd 2020

Registered in England and Wales 08985867

Site Links

RSSLoginLink Cookie PolicySitemap

Social Media

facebook.com/Claytabaseinstagram.com/claytabase/twitter.com/Claytabaselinkedin.com/company/claytabase-ltd

Get in Touch

+442392064871info@claytabase.co.ukClaytabase Ltd, Unit 3d, Rink Road Industrial Estate, PO33 2LT, United Kingdom

Partnered With

The settings on this site are set to allow all cookies. These can be changed on our Cookie Policy & Settings page.
By continuing to use this site you agree to the use of cookies.
Ousia Logo
Logout
Ousia CMS Loader