|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, March 13, 2012 9:05 AM
Points: 24,
Visits: 40
|
|
Hello,
I have an issue where I am storing various international characters in nvarchar columns, but need to branch the data at one point of processing so that ASCII characters are run through an additional cleansing process and all non-ASCII characters are set aside.
Is there a way to identify which nvarchar values are within the ASCII range and can be converted to varchar without corruption? Also, the strings may contain a mix of english and international character sets, so the entire string must be checked and not just the first character.
i.e. Pass: 'Hello', 'abc123'
Fail: '太平市', 'abc太123'
Any help would be appreciated and let me know if examples would make this more clear.
Regards, Chris
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Today @ 2:54 PM
Points: 31,410,
Visits: 13,726
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, March 13, 2012 9:05 AM
Points: 24,
Visits: 40
|
|
Thanks Steve, this may be an option if we cannot figure out a better way around this. I just need to confirm that we are not allowing ? characters to exist in any of the strings I am cleansing and, if so, create some type of internal process for escaping these out so they do not trigger the 'international' flag.
Appreciate the help.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 6:56 PM
Points: 11,613,
Visits: 27,669
|
|
proof of concept for Steve's idea;i thought that was kind of neat:
--results: Status cnv id val id val ------ ------------------------------ ----------- ------- ----------- ------- Pass Hello 1 Hello 1 Hello Pass abc123 2 abc123 2 abc123 Fail ??? 3 太平市 3 太平市 Fail abc?123 4 abc太123 4 abc太123
the test code:
SELECT 1 as id,N'Hello' As val INTo #TMP UNION ALL SELECT 2 as id,N'abc123' UNION ALL SELECT 3 as id,N'太平市' UNION ALL SELECT 4 as id,N'abc太123'
SELECT CASE WHEN t1.val = CONVERT(varchar,t2.val) THEN 'Pass' ELSE 'Fail' END As Status, CONVERT(varchar,t2.val) As cnv,* FROM #TMP t1 LEFT OUTER JOIN #TMP t2 ON t1.Id = t2.ID
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, March 13, 2012 9:05 AM
Points: 24,
Visits: 40
|
|
Thanks for the code Lowell, I have been playing around with this myself and it looks like it is going to work out well for my problem.
Thanks again both of you for the help!
|
|
|
|