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.
| Author |
Topic |
|
AKP2008
Starting Member
45 Posts |
Posted - 2008-12-29 : 04:33:00
|
| Hi All,I want to generate random 9 digit number with below conditions.charat(1+3) positions - charat (5+7) positions = charat 9th positionFor example my number is 123456788.(1 + 3) - (5+7) = 8So 9th character should be 8. This is my requirement.How can i do this?Please help me. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-12-29 : 08:51:35
|
| [code]select number*10+abs((number/10000000+number/100000%10)-(number/1000%10+number/10%10)) as number from( select number/power(10,len(number)-case when len(number)>=8 then 8 else 0 end) as number from ( select top 10000 abs(checksum(newid())) as number from sysobjects s1 cross join sysobjects s2 ) as T) as t[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-12-29 : 10:50:48
|
| If I understand the req correctly you are kind of generating a "check digit". What happens if the first 8 digits are: 21146281(2+1) - (6+8) = -14even if you ABS the result you end up with a 2 digit number so what should the ninth digit be?Be One with the OptimizerTG |
 |
|
|
|
|
|