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 |
|
priyasunkar
Starting Member
3 Posts |
Posted - 2012-01-04 : 10:55:53
|
| Hi,i need to generate 3 random seed for SSN.For example: 123 45 6789 is the SSNthen i need to replace 1 with some random number and 4 with some random number and 6 with some random number.how can i do that?Please help me..Thankyou. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
priyasunkar
Starting Member
3 Posts |
Posted - 2012-01-04 : 14:38:01
|
| Thanks Visakh..:)Thanks Brett..im doing data scrambling for the SSN...can you give an idea of algorithm how do i need to start working on it would realyy helps..Thank you |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2012-01-04 : 23:58:44
|
| [code]select aa.*from ( select a.*, NEW_SSN = -- left random digit (1 to 9) (((convert(bigint,convert(varbinary(7),newid()))%9)+1)*100000000)+ -- next two digits (((ssn%100000000)/1000000)*1000000)+ -- next random digit (0 to 9) ((convert(bigint,convert(varbinary(7),newid()))%10)*100000)+ -- next digits (((ssn%100000)/10000)*10000)+ -- last random digit (0 to 9) ((convert(bigint,convert(varbinary(7),newid()))%10)*1000)+ -- last 3 digits (ssn%1000) from ( -- test values select ssn = 123456789 union all select ssn = 178463458 ) a cross join ( --generate rows select top 8 x=1 from syscolumns ) b ) aawhere -- eliminate dupes aa.SSN <> aa.NEW_SSNgroup by -- eliminate dupe rows aa.SSN, aa.NEW_SSNorder by aa.SSN, aa.NEW_SSN[/code]Results:[code]ssn NEW_SSN----------- --------------------123456789 123552789123456789 223457789123456789 423753789123456789 623855789123456789 723657789123456789 823159789123456789 823753789123456789 923154789178463458 178160458178463458 478360458178463458 478666458178463458 578360458178463458 578369458178463458 678764458178463458 778866458178463458 978564458(16 row(s) affected)[/code]CODO ERGO SUM |
 |
|
|
priyasunkar
Starting Member
3 Posts |
Posted - 2012-01-05 : 12:12:06
|
| It works great thank you so much Micheal... |
 |
|
|
|
|
|
|
|