[英]Convert Alphanumeric value to a unique numeric value in SQL
I have a table column with values like below 我有一个表列,其值如下所示
V5H 3K3
V6L 4L4
V4E 5L2
V5H 3K3
I need to get a unique number against each of them so it would look something like 我需要针对他们每个人获得一个唯一的号码,以便看起来像
V5H 3K3 1111
V6L 4L4 2222
V4E 5L2 3333
V5H 3K3 1111
Is there a simple function in SQL Server that can be used to do this? SQL Server中是否有一个简单的函数可用于执行此操作?
Select cast(HashBytes('MD5', 'V5H 3K3') as int)
Returns -381163718 返回-381163718
For Example 例如
Declare @Table table (SomeField varchar(25))
Insert into @Table values
('V5H 3K3'),
('V6L 4L4'),
('V4E 5L2'),
('V5H 3K3')
Select *,AsAnInt = abs(cast(HashBytes('MD5', SomeField) as int))
From @Table
Returns 退货
SomeField AsAnInt
V5H 3K3 381163718
V6L 4L4 245350301
V4E 5L2 1706996605
V5H 3K3 381163718
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.