This function takes a UK NHS Number as an input variable and checks to see if that NHS Number is or isn't valid.
This uses the Modulus 11 algorithm which is mandatory for checking the NHS Number.
https://www.datadictionary.nhs.uk/attributes/nhs_number.html
After a discussion with one of our clients, we got to talking about NHS Numbers and how they are validated. We did some research and it got us interested so we decided to create a T-SQL function that can validate an NHS Number automatically.
Remember, don't use scalar functions in views, performance will tank, this function is a decent proof of concept as to how you can validate the NHS Number in your own projects if required.
It is possible to get dummy NHS Numbers from here which you can use for testing this function.
Once you have added the NHS Number to your database of choice, you can use it like this
SELECT [dbo].[fnNHSValidation_svf]('6043153327')
SELECT [dbo].[fnNHSValidation_svf](NHSNumber) FROM Patients