开发者

SQL Server 2008 search double byte characters

Is there a way to tell which records are double byte character in SQL Server 2008?

For example, I want to query all records in Chinese, Korean and Japanese in a table if country filed is blank, how can I do it?

Your input is really appreciated.

I think I might have confused you guys. Everything is stored in nvarchar. Some records are in Chinese, some are in Korean, Some are in Spanish an开发者_如何学Pythond more. We want to find out the Chinese, Japanese and Korean records to do something about it. Does that make sense?


Is there a way to tell which records are double byte character in SQL Server 2008?

You can use this - if the double-byte character cannot be reduced to a single byte, then you have CJK in the record:

select * from tbl
where convert(nvarchar(max),convert(varchar(max),somecolumn)) != somecolumn


If I understand you, then it could be as simple as a stored proc like this:

DECLARE @SearchString nvarchar(MAX)
...
SELECT * FROM MyTable
WHERE Country = '' and SearchField = @SearchString

This assumes that SearchField is nvarchar.

If you have a nvarchar column then all information in there will be double byte.

If you are trying to find all columns that are of type nvarchar then you can use the query below:

SELECT OBJECT_NAME(col.OBJECT_ID) as [TableName], col.[name] as [ColName], typ.[name]
FROM sys.all_columns col
INNER JOIN sys.types typ
ON col.user_type_id = typ.user_type_id
WHERE col.user_type_id = 231
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜