How to validate the ICCID number of a SIM card in TSQL?

How to validate the ICCID number of a SIM card in TSQL?

Content Index :

How to validate the ICCID number of a SIM card in TSQL?
Tag : sql-server , By : moops
Date : November 24 2020, 01:01 AM

may help you . I have been wondering if there is the possibility of validating that big number that is the unique code for every SIM card on the planet, the ICCID. , I Found it!
CREATE FUNCTION dbo.usp_ValidateICCID ( @inputString VARCHAR(20) )


IF @inputString NOT LIKE ('%[0-9]%[0-9]%[0-9]%') 

DECLARE @charTable TABLE ( 
 Position INT NOT NULL, 
 ThisChar CHAR(1) NOT NULL, 
 Doubled TINYINT, 
 Summed TINYINT ) 

SET @inputString = CAST(@inputString AS CHAR(20))
INSERT INTO @charTable(Position, ThisChar) 
 SELECT 1, SUBSTRING(@inputString, 1, 1) UNION ALL 
 SELECT 2, SUBSTRING(@inputString, 2, 1) UNION ALL 
 SELECT 3, SUBSTRING(@inputString, 3, 1) UNION ALL 
 SELECT 4, SUBSTRING(@inputString, 4, 1) UNION ALL 
 SELECT 5, SUBSTRING(@inputString, 5, 1) UNION ALL 
 SELECT 6, SUBSTRING(@inputString, 6, 1) UNION ALL 
 SELECT 7, SUBSTRING(@inputString, 7, 1) UNION ALL 
 SELECT 8, SUBSTRING(@inputString, 8, 1) UNION ALL 
 SELECT 9, SUBSTRING(@inputString, 9, 1) UNION ALL 
 SELECT 10, SUBSTRING(@inputString, 10, 1) UNION ALL 
 SELECT 11, SUBSTRING(@inputString, 11, 1) UNION ALL 
 SELECT 12, SUBSTRING(@inputString, 12, 1) UNION ALL 
 SELECT 13, SUBSTRING(@inputString, 13, 1) UNION ALL 
 SELECT 14, SUBSTRING(@inputString, 14, 1) UNION ALL 
 SELECT 15, SUBSTRING(@inputString, 15, 1) UNION ALL 
 SELECT 16, SUBSTRING(@inputString, 16, 1) UNION ALL 
 SELECT 17, SUBSTRING(@inputString, 17, 1) UNION ALL 
 SELECT 18, SUBSTRING(@inputString, 18, 1) UNION ALL 
 SELECT 19, SUBSTRING(@inputString, 19, 1) UNION ALL 
 SELECT 20, SUBSTRING(@inputString, 20, 1)

DELETE FROM @charTable
WHERE  ThisChar NOT LIKE('[0-9]') 

DECLARE @tempTable TABLE ( 
 NewPosition INT IDENTITY(1,1), 
 OldPosition INT ) 
INSERT INTO @tempTable (OldPosition)
 SELECT Position 
 FROM @charTable 
 ORDER BY Position ASC 

UPDATE  @charTable
SET   Position = t2.NewPosition 
FROM  @charTable t1 
INNER JOIN  @tempTable t2 ON t1.Position = t2.OldPosition 

IF ( SELECT MAX(Position) % 2 FROM @charTable ) = 0 
 UPDATE @charTable
 SET  Doubled = CAST(ThisChar AS TINYINT) * 2 
 WHERE Position % 2 <> 0 
 UPDATE @charTable 
 SET  Doubled = CAST(ThisChar AS TINYINT) * 2 
 WHERE Position % 2 = 0 

UPDATE @charTable
SET  Summed = 
     WHEN Doubled IS NOT NULL AND Doubled <= 9 
     THEN Doubled 
     WHEN Doubled IS NOT NULL AND Doubled >= 10 
     THEN (Doubled / 10) + (Doubled - 10) 

IF ( SELECT SUM(Summed) % 10 FROM @charTable ) = 0
 SET @result = 1
 SET @result = 0

RETURN @result 

alter function dbo.usp_ValidaICCID(@inputStr varchar(20))
    RETURNS tinyint
as begin
  declare @workStr   varchar(20)
  declare @strLength smallint
  declare @i         smallint
  declare @sum       smallint
  declare @prod      smallint
  declare @digit     char(1)
  declare @evenInd   tinyint
  declare @result    tinyint
  if(@inputStr not LIKE ('%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]'))
        return 2
  set @strLength = len ( @inputStr )
  set @i = 1
  set  @workStr = ''
  WHILE @i <= @strLength
    set @digit = SUBSTRING(@inputStr, @i, 1)
    if(@digit LIKE '[0-9]') set @workStr = @workStr + @digit
    set @i = @i +1
  set @sum     = 0
  set @evenInd = 0
  if(@strLength % 2 = 0)
     set @evenInd = 1
  set @i = 1
  WHILE @i <= @strLength
    set @digit = SUBSTRING(@workStr, @i, 1)
    set @prod   = CONVERT(smallint , @digit)
    if(@evenInd = 1 and @i % 2 = 1 or @evenInd = 0 and @i % 2 = 0) set @prod = @prod * 2
    if(@prod >= 10)  set @prod = @prod/10 + @prod-10 
    set @sum = @sum + @prod
    set @i = @i +1
  if(@sum %10 = 0)
     set @result = 1 
   set @result = 0 
  return @result

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to validate credit card number and Card Code Verification (ccv)

Tag : php , By : leorick
Date : March 29 2020, 07:55 AM
Any of those help Right, so after some initial fail on understanding what was being asked for, I think the following should help.

How to get ICCID number from IPhone?

Tag : iphone , By : Jonathan Bernard
Date : March 29 2020, 07:55 AM
This might help you I am Trying to get the ICCID from Iphone. can anyone please help me on this. , You mean via programming method? You can't.

How can I get the ICCID number of the phone?

Tag : android , By : sgmichelsen
Date : March 29 2020, 07:55 AM
Hope that helps I believe getSimSerialNumber() will get iccid.
For Android 5.1+, see this answer on this question, for which I deserve zero credit.

How to get sim ICCID number on Windows Phone 8

Tag : chash , By : bjorngylling
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Very old question, but I have the answer in case some other people came here for the same issue.
Is possibile to get the phone IMEI only if you request OEM Access and libraries to Microsoft itelf. They provide OEM partner some Restricted API. I think they only release those api to mobile operator

how to validate credit card info(billing, card number etc) through authorize.net?

Tag : php , By : user142345
Date : March 29 2020, 07:55 AM
wish of those help No. The only way to know a credit card is valid is to process a transaction. Only then is the bank contacted to validate the credit card.
FYI, I am the author of the article you linked to.
Related Posts Related QUESTIONS :
  • What is best practice for FTP from a SQL Server 2005 stored procedure?
  • How to enable Full-text Indexing in SQL Server 2005 Express?
  • How do I know which SQL Server 2005 index recommendations to implement, if any?
  • T-Sql Remove Decimal Point From Money Data Type
  • How do I Transform Sql Columns into Rows?
  • SQL Client for Mac OS X that works with MS SQL Server
  • SQL Server 2000: Is there a way to tell when a record was last modified?
  • How to remove the time portion of a datetime value (SQL Server)?
  • I need to know how much disk space a table is using in SQL Server
  • What's the best way to determine if a temporary table exists in SQL Server?
  • Calculate the row value based on different formula
  • how to set two variables for the same column?
  • Debezium Error : ConnectException: Data row is smaller than a column index
  • TSQL -- find records in table with multiples in one column, and at least one specific occurrence of a value in another c
  • Table-Valued Parameter Recieving Invalid Data Type Error
  • UPDATE PERMISSION without ALTER permission
  • How to determine a table's dependencies?
  • Creating Dynamic Pivot Table Column Names
  • How to debug CLR database object (stored procedure) using Visual Studio 2019
  • DROP TABLE fails for temp table
  • Why might SQL execute more quickly on SQL Server 2000 when NOT using a stored procedure?
  • cmd line SQL server 2008 express install
  • Sql server query using function and view is slower
  • Does anyone have a backup strategy for SQL Azure databases?
  • Accessing SQL Server using an IP Address and Port Number ... Help!
  • how to create simulator for web application for load test and stress test
  • when a sql server agent job is created and scheduled should we start running the job manually for the first time or will
  • Split BulkColumn into Rows
  • Naming a Column using Variable
  • T-SQL Slowly Changing Dimension - Multiple Updates, Single Action Output?
  • SQL Output as XML namespace
  • Using Wildcard For Range of Characters In T-SQL
  • Azure SQL Server Elastic query with ApplicationIntent ReadOnly
  • How to get date ranges according to date data inside database table
  • How to get those records that contains every items mentioned in where clause
  • SQL Trigger on insert, only for new rows
  • Recursively replace string using a CTE
  • How to merge multiple column into one column with same table in SQL Server?
  • Designing stored procedure to work with Multiple Tables which have different formats and logic
  • How to select SQL Server table as tab delimited string
  • How to delete specific range of records from a GROUP BY query?
  • SAS dsnless connection to SQL server not working even if OLEDB is installed
  • How to correct an error in SELECT statement
  • All cases when check constraints are executed for each row
  • Exporting database data to csv in classic asp
  • Why does this char value not convert to datetime?
  • How to get file type from binary data in SQL Server File table?
  • Reading derived column expression
  • How do I persist sales price in an orders details table?
  • How to extract data from xml nodes as table from column?
  • Removing Leading and Trailing Zeros along with a Case
  • How to insert new line Char(13) in T-SQL
  • Get first date record from multiple records
  • SQL Server Procedure Returning -1
  • Underscore in Where clause yields unexpected result, why?
  • How to calculate the SID for new logins?
  • Purpose of defining parameters in Access query
  • Windows API call "RegGetValueW" returned error code: 0
  • How to convert CURSOR based query in to SET based
  • Why my main query is running successfully at the same time as subquery returns an error?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com