Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 ISBN algorithms
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 08/24/2007 :  08:21:42  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Here is how you get the check digit for ISBN.
CREATE FUNCTION dbo.fnGetISBN
(
	@ISBN VARCHAR(11)
)
RETURNS VARCHAR(13)
AS
BEGIN
	DECLARE	@Index TINYINT,
		@Weight TINYINT,
		@Sum SMALLINT

	SELECT	@Index = LEN(@ISBN),
		@Weight = 2,
		@Sum = 0

	WHILE @Index > 0
		BEGIN
			IF SUBSTRING(@ISBN, @Index, 1) <> '-'
				SELECT	@Sum = @Sum + @Weight * CAST(SUBSTRING(@ISBN, @Index, 1) AS TINYINT),
					@Weight = @Weight + 1

			SET @Index = @Index - 1
		END

	RETURN	CASE @Sum % 11
			WHEN 1 THEN @ISBN + '-X'
			ELSE @ISBN + '-' + CONVERT(CHAR(1), 11 - (@Sum % 11))
		END
END


E 12°55'05.25"
N 56°04'39.16"

Edited by - SwePeso on 08/24/2007 08:21:56

spirit1
Cybernetic Yak Master

Slovenia
11752 Posts

Posted - 08/24/2007 :  08:27:10  Show Profile  Visit spirit1's Homepage  Reply with Quote
too much time again?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22864 Posts

Posted - 08/24/2007 :  08:34:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by spirit1

too much time again?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp


No doubt

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000