Well, what you have is a string of 32 Unicode characters encoded as UTF-16 BE, consisting of:062F 062C 0627 0633 0641 0637 062F 0628 0627nine Arabic letters: dal jeem alef seen feh tah dal beh alef0020one space0633 062F 0641 062F 062C 0633 0646 062C 062Fnine Arabic letters: seen dal feh dal jeem seen noon jeem dal0020one space0038 0036 0030 0034 0039 0032 0031 0039 0030 0036 0030 0032twelve (Basic Latin) digits: 8 6 0 4 9 2 1 9 0 6 0 2So you have three things to do:1. Get the characters into the right type (nvarchar)2. Decide where the digits start3. Turn the digits into a numeric typeThe biggest problem is the first part, since SQL Server stores Unicode strings as UTF-16 LE.I'd suggest you write a function like this to swap the bytes:CREATE FUNCTION dbo.ByteSwap(@in varbinary(8000))RETURNS varbinary(8000)ASBEGIN DECLARE @b int, @l int, @res varbinary(8000) SELECT @b = 1, @res = 0x, @l = LEN(@in) WHILE @b <= @l BEGIN SET @res = @res + SUBSTRING(@in, @b+1,1) + SUBSTRING(@in, @b, 1) SET @b = @b + 2 END RETURN @resEND
Once you have that, the rest if fairly straightforward:DECLARE @s varbinary(64)SET @s = 0x062F062C0627063306410637062F062806270020 + 0x0633062F0641062F062C06330646062C062F0020 + 0x003800360030003400390032003100390030003600300032SELECT s, LEFT(s, first_digit - 2) AS the_words, CAST(SUBSTRING(s, first_digit, 64) AS bigint) AS the_numberFROM ( SELECT s, PATINDEX('%[0-9]%', s) AS first_digit FROM ( SELECT CAST(dbo.ByteSwap(@s) AS nvarchar(32)) AS s ) AS A ) AS A