Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 mod 10 weights 1, 2 Rate Topic Display Mode Topic Options
Author
 Message
 Posted Thursday, January 7, 2010 1:02 PM
 Grasshopper Group: General Forum Members Last Login: Thursday, May 1, 2014 11:46 PM Points: 19, Visits: 158
 It is a MOD-10 summation digits based on weights of 1,2........ now i would like achive that within SQL 2000 ..... is it possible with... i am new to sql 2000, so please bare with mef1 i have input data and f2 i like to show the calcuated result.' Note the following source code is designed to calculate a check digit for:' a Mod 10 Sum of Values check digit routine that uses the 1, 2 weighting.' Characters are read from left to right in performing the calculation.Public Function DetermineCheckDigit(ByVal Sequence As String) As Integer Dim intAscVal As Integer Dim intCalcCheckDigit As Integer Dim intI As Integer Dim intLen As Integer Dim intRmndr As Integer Dim intSum As Integer Dim intTemp1 As Integer Dim intValues() As Integer Dim intWeight As Integer 'Calculate numeric intValues of string characters intLen = Len(Sequence) ReDim intValues(intLen) For intI = 1 To intLen intAscVal = Asc(Mid\$(Sequence, intI, 1)) 'If numeric, keep as is If (intAscVal >= 48 And intAscVal <= 57) Then intValues(intI) = intAscVal - 48 'If non-numeric, use replacement value ElseIf (intAscVal >= 65 And intAscVal <= 90) Then Select Case Chr\$(intAscVal) Case "A", "K", "U" intValues(intI) = 0 Case "B", "L", "V" intValues(intI) = 1 Case "C", "M", "W" intValues(intI) = 2 Case "D", "N", "X" intValues(intI) = 3 Case "E", "O", "Y" intValues(intI) = 4 Case "F", "P", "Z" intValues(intI) = 5 Case "G", "Q" intValues(intI) = 6 Case "H", "R" intValues(intI) = 7 Case "I", "S" intValues(intI) = 8 Case "J", "T" intValues(intI) = 9 Case Else intValues(intI) = 0 End Select Else intValues(intI) = 0 End If Next intI 'Start weighting each value with using Mod-10 weights (1-2) intWeight = 1 intSum = 0 For intI = 1 To intLen intTemp1 = (intWeight * intValues(intI)) intSum = intSum + intTemp1 intWeight = intWeight + 1 If (intWeight > 2) Then intWeight = 1 Next intI 'Drop all but last digit intRmndr = (intSum Mod 10) If (intRmndr = 0) Then intRmndr = 10 End If intCalcCheckDigit = 10 - intRmndr DetermineCheckDigit = intCalcCheckDigitEnd Function
Post #843831
 Posted Thursday, January 7, 2010 1:24 PM
 SSCrazy Group: General Forum Members Last Login: Friday, December 2, 2016 3:06 PM Points: 2,532, Visits: 4,503
 I don't think you're going to find too many people here who are going to be able to (or even want) to go through your VB code.Better: can you give us examples of the data (not the code) input and output you're looking for? And please keep it simple, short, and sweet.Thanks! +--------------------------------------------------------------------------------------+Check out my blog at https://pianorayk.wordpress.com/
Post #843842
 Posted Thursday, January 7, 2010 1:50 PM
 SSChampion Group: General Forum Members Last Login: Yesterday @ 8:07 PM Points: 14,543, Visits: 38,400
 i think you are looking for the LUHN mod 10 credit card validation, right? googling "TSQL LUHN mod 10"got me this tsql code snippet"http://www.novicksoftware.com/UDFofWeek/Vol2/T-SQL-UDF-Vol-2-Num-47-udf_Bank_IsLuhn.htm Lowell--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #843860
 Posted Thursday, January 7, 2010 3:19 PM
 SSC-Insane Group: General Forum Members Last Login: Yesterday @ 5:43 PM Points: 23,516, Visits: 37,735
 Assuming you have a Tally table, how about the following code:`declare @ TestData varchar(12);set @TestData = '03EA12J77';select (10 - (sum( (((N + 1) % 2) + 1) * case when substring(@ TestData, N, 1) in ('0','A','K','U') then 0 when substring(@ TestData, N, 1) in ('1','B','L','V') then 1 when substring(@ TestData, N, 1) in ('2','C','M','W') then 2 when substring(@ TestData, N, 1) in ('3','D','N','X') then 3 when substring(@ TestData, N, 1) in ('4','E','O','Y') then 4 when substring(@ TestData, N, 1) in ('5','F','B','Z') then 5 when substring(@ TestData, N, 1) in ('6','G','Q') then 6 when substring(@ TestData, N, 1) in ('7','H','R') then 7 when substring(@ TestData, N, 1) in ('8','I','S') then 8 when substring(@ TestData, N, 1) in ('9','J','T') then 9 else 0 end ) % 10)) % 10from dbo.Tallywhere N <= len(@TestData);`You will need to remove the space I had to enter between @ sign and the T in the variable name to get this to post.If you don't have a Tally table, here is a link to an article about them:http://www.sqlservercentral.com/articles/T-SQL/62867/.
Post #843931
 Posted Thursday, January 7, 2010 4:31 PM
 Grasshopper Group: General Forum Members Last Login: Thursday, May 1, 2014 11:46 PM Points: 19, Visits: 158
 Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.Server: Msg 8116, Level 16, State 1, Line 3Argument data type nvarchar is invalid for argument 2 of substring function.showing me above error in query analyzer i posted folowing code declare @TestData varchar(12);set @TestData = '03EA12J77';select (10 - (sum( (((N + 1) % 2) + 1) * case when substring(@TestData, N, 1) in ('0','A','K','U') then 0 when substring(@TestData, N, 1) in ('1','B','L','V') then 1 when substring(@TestData, N, 1) in ('2','C','M','W') then 2 when substring(@TestData, N, 1) in ('3','D','N','X') then 3 when substring(@TestData, N, 1) in ('4','E','O','Y') then 4 when substring(@TestData, N, 1) in ('5','F','B','Z') then 5 when substring(@TestData, N, 1) in ('6','G','Q') then 6 when substring(@TestData, N, 1) in ('7','H','R') then 7 when substring(@TestData, N, 1) in ('8','I','S') then 8 when substring(@TestData, N, 1) in ('9','J','T') then 9 else 0 end ) % 10)) % 10from dbo.Tallywhere N <= len(@TestData);
Post #843983
 Posted Thursday, January 7, 2010 5:55 PM
 SSC-Insane Group: General Forum Members Last Login: Yesterday @ 5:43 PM Points: 23,516, Visits: 37,735
 N is the column name in my Tally table (dbo.Tally). Do you have a Tally table? If so, what is the name of the column in your Tally table? You will need to replace the N in my query with that column name.If you don't have a Tally table, you need to create one.
Post #844020
 Posted Thursday, January 7, 2010 8:45 PM
 SSC-Forever Group: General Forum Members Last Login: Yesterday @ 9:30 PM Points: 42,060, Visits: 39,443
 Lynn Pettis (1/7/2010)Assuming you have a Tally table, how about the following code:`declare @ TestData varchar(12);set @TestData = '03EA12J77';select (10 - (sum( (((N + 1) % 2) + 1) * case when substring(@ TestData, N, 1) in ('0','A','K','U') then 0 when substring(@ TestData, N, 1) in ('1','B','L','V') then 1 when substring(@ TestData, N, 1) in ('2','C','M','W') then 2 when substring(@ TestData, N, 1) in ('3','D','N','X') then 3 when substring(@ TestData, N, 1) in ('4','E','O','Y') then 4 when substring(@ TestData, N, 1) in ('5','F','B','Z') then 5 when substring(@ TestData, N, 1) in ('6','G','Q') then 6 when substring(@ TestData, N, 1) in ('7','H','R') then 7 when substring(@ TestData, N, 1) in ('8','I','S') then 8 when substring(@ TestData, N, 1) in ('9','J','T') then 9 else 0 end ) % 10)) % 10from dbo.Tallywhere N <= len(@TestData);`You will need to remove the space I had to enter between @ sign and the T in the variable name to get this to post.If you don't have a Tally table, here is a link to an article about them: http://www.sqlservercentral.com/articles/T-SQL/62867/.Just curious... why are you substacting the mod 10 checksum from 10?Also, the bold enhancement on your link broke the link. --Jeff Moden"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." Helpful Links:How to post code problemsHow to post performance problems
Post #844071
 Posted Thursday, January 7, 2010 9:04 PM
 SSC-Forever Group: General Forum Members Last Login: Yesterday @ 9:30 PM Points: 42,060, Visits: 39,443
 I don't know which will be faster nor which you prefer to read nor am I sure which is correct (I don't subtract my result from 10 like Lynn did... I do it like they do for Luhn Mod 10 Check Sums for Credit Cards).The other thing to remember is that if you use such a thing on credit cards, the right-most digit will always be treated as a "1" multiplier and then you work to the left in 1-2 order...`DECLARE @TestData VARCHAR(12), @ControlString CHAR(36) SELECT @TestData = '03EA12J78', @ControlString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' SELECT SUM(((N+1)%2+1)*(CHARINDEX(SUBSTRING(@TestData, N, 1),@ControlString)-1))%10 FROM dbo.Tally WHERE N <= LEN(@TestData)` --Jeff Moden"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." Helpful Links:How to post code problemsHow to post performance problems
Post #844076
 Posted Thursday, January 7, 2010 9:09 PM
 SSC-Forever Group: General Forum Members Last Login: Yesterday @ 9:30 PM Points: 42,060, Visits: 39,443
 Never mind, Lynn... I see why you're subtracting from 10... I did a validation of a full number and you're calculating the check digit.Modification of my code will change it from validation to calculating the check digit...`DECLARE @TestData VARCHAR(12), @ControlString CHAR(36) SELECT @TestData = '03EA12J78', @ControlString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' SELECT 10-(SUM(((N+1)%2+1)*(CHARINDEX(SUBSTRING(@TestData, N, 1),@ControlString)-1))%10) FROM dbo.Tally WHERE N <= LEN(@TestData)` --Jeff Moden"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." Helpful Links:How to post code problemsHow to post performance problems
Post #844077
 Posted Thursday, January 7, 2010 10:01 PM
 SSC-Insane Group: General Forum Members Last Login: Yesterday @ 5:43 PM Points: 23,516, Visits: 37,735
 Fixed the link in my previous post. Thanks Jeff.
Post #844082

 Permissions