[dba-SQLServer] SQL vin check sum

Mark A Matte markamatte at hotmail.com
Thu Mar 29 12:56:10 CDT 2012


It was a pain searching for a keyword of sql and vin...but finally stumbled across this:
http://www.mombu.com/microsoft/sql-server/t-help-with-t-sql-coding-297549.html
 
I added a modification though...it does NOT handle invalid characters...so it would tell you a vin was good(or bad) after the checksum even though an invalid character was passed.
 
After the :
SELECT @value = Value
FROM Vin_Digit
WHERE Digit = SUBSTRING(@Vin, @position, 1)
 
I added to this check for null meaning the character was NOT valid:
IF @value is null
SET @MyError = 'X' -- Bad Character
 
Also...you have to populate the 2 tables created with the correct values...if you are already working with vins/checksum...you will know which to populate.
 
Hope it helps...
 
Mark A. Matte
 
 
 

> Date: Thu, 29 Mar 2012 08:43:13 -0700
> From: davidmcafee at gmail.com
> To: dba-sqlserver at databaseadvisors.com
> Subject: Re: [dba-SQLServer] SQL vin check sum
> 
> Care to share? I'd like to see it.
> 
> On Thu, Mar 29, 2012 at 8:31 AM, Mark A Matte <markamatte at hotmail.com>wrote:
> 
> >
> > Thanks David,
> >
> > I had looked at those...but I just found a UDF sample online.
> >
> > Worked good.
> >
> > Thanks,
> >
> > mark A. Matte
> >
> >
> > > Date: Tue, 27 Mar 2012 14:29:09 -0700
> > > From: davidmcafee at gmail.com
> > > To: dba-sqlserver at databaseadvisors.com
> > > Subject: Re: [dba-SQLServer] SQL vin check sum
> > >
> > > I don't, but maybe these links can help
> > >
> > > http://en.wikipedia.org/wiki/Vehicle_Identification_Number
> > >
> > >
> > http://en.wikibooks.org/wiki/Vehicle_Identification_Numbers_%28VIN_codes%29/Check_digit
> > >
> > >
> > > On Tue, Mar 27, 2012 at 1:59 PM, Mark A Matte <markamatte at hotmail.com
> > >wrote:
> > >
> > > >
> > > > Hello All,
> > > >
> > > > Anyone have a SQL based "VIN Check Sum" Function I can borrow to test
> > if a
> > > > VIN is valid...for United States Vehicle Identification Number?
> > > >
> > > > Thanks,
> > > >
> > > > Mark A. Matte
> > > >
> > > > _______________________________________________
> > > > dba-SQLServer mailing list
> > > > dba-SQLServer at databaseadvisors.com
> > > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> > > > http://www.databaseadvisors.com
> > > >
> > > >
> > > _______________________________________________
> > > dba-SQLServer mailing list
> > > dba-SQLServer at databaseadvisors.com
> > > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> > > http://www.databaseadvisors.com
> > >
> >
> > _______________________________________________
> > dba-SQLServer mailing list
> > dba-SQLServer at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> > http://www.databaseadvisors.com
> >
> >
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
> 
 		 	   		  


More information about the dba-SQLServer mailing list