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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 ISBN 10-->13

Author  Topic 

razr
Starting Member

2 Posts

Posted - 2010-02-22 : 09:05:45
Is there any AS IS script available for converting ISBN10 to ISBN13 into SQL?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-22 : 10:51:08
[code]
declare @isbn10 varchar(10),
@isbn13 varchar(13),
@i int,
@chk int

select @isbn10 = '0123456479'

select @isbn13 = '978' + left(@isbn10, 9)

select @i = 1,
@chk = 0

while @i <= 9
begin
select @chk = @chk + (substring(@isbn10, @i, 1) * case when @i % 2 = 1 then 1 else 3 end)
select @i = @i + 1
end

select @chk = 10 - (@chk % 10)

select @isbn13 = @isbn13 + convert(char(1), @chk)

select @isbn13
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

razr
Starting Member

2 Posts

Posted - 2010-02-22 : 11:46:02
Ty!!

Would this cover also ISBN10s with the X char at the end ?

for example: 185109606X ?
Go to Top of Page
   

- Advertisement -