Collation Is A Problem
My first project in the company went live last evening. I could say everything was like bells and whistles except Chinese display in Crystal Report. I was a little confused at the beginning for these two servers installed same Windows 2000 Advanced Server, same SQL Server 2000 with same service pack. What's more, simiplified Chinese and traditional Chinese support is fine, we could visited Chinese web site with no pain. So, ...
The real cause is these two database servers used different collations, the UAT one is using its default which is Chinese_PRC_CI_AS while the live one is also using its default collation but this time its default is Latin.
Create a new SQL server database with collation set to same as the UAT server, everything is fine.
And one more tricky problem, this time with creating stored procedure. SQL server always warned "Cannot resolve collation conflict for equal to operation" when saved/applied, but it is the same as another database. Since the previous stored procedure had no problem. I guessed it was because of what returned from functon fnSplit as it returns a table of varchar with default collation. So I changed the function as below and it was fixed:
CREATE FUNCTION [webotis].fn_Split(@sText varchar(8000), @sDelim varchar(20) = ' ')
RETURNS @retArray TABLE (idx smallint Primary Key, value varchar(8000) COLLATE Chinese_PRC_CI_AS)
AS
BEGIN
DECLARE @idx smallint,
@value varchar(8000),
@bcontinue bit,
@iStrike smallint,
@iDelimlength tinyint
IF @sDelim = 'Space'
BEGIN
SET @sDelim = ' '
END
SET @idx = 0
SET @sText = LTrim(RTrim(@sText))
SET @iDelimlength = DATALENGTH(@sDelim)
SET @bcontinue = 1
IF NOT ((@iDelimlength = 0) or (@sDelim = 'Empty'))
BEGIN
WHILE @bcontinue = 1
BEGIN
--If you can find the delimiter in the text, retrieve the first element and
--insert it with its index into the return table.
IF CHARINDEX(@sDelim, @sText)>0
BEGIN
SET @value = SUBSTRING(@sText,1, CHARINDEX(@sDelim,@sText)-1)
BEGIN
INSERT @retArray (idx, value)
VALUES (@idx, @value)
END
--Trim the element and its delimiter from the front of the string.
--Increment the index and loop.
SET @iStrike = DATALENGTH(@value) + @iDelimlength
SET @idx = @idx + 1
SET @sText = LTrim(Right(@sText,DATALENGTH(@sText) - @iStrike))
END
ELSE
BEGIN
--If you can’t find the delimiter in the text, @sText is the last value in
--@retArray.
SET @value = @sText
BEGIN
INSERT @retArray (idx, value)
VALUES (@idx, @value)
END
--Exit the WHILE loop.
SET @bcontinue = 0
END
END
END
ELSE
BEGIN
WHILE @bcontinue=1
BEGIN
--If the delimiter is an empty string, check for remaining text
--instead of a delimiter. Insert the first character into the
--retArray table. Trim the character from the front of the string.
--Increment the index and loop.
IF DATALENGTH(@sText)>1
BEGIN
SET @value = SUBSTRING(@sText,1,1)
BEGIN
INSERT @retArray (idx, value)
VALUES (@idx, @value)
END
SET @idx = @idx+1
SET @sText = SUBSTRING(@sText,2,DATALENGTH(@sText)-1)
END
ELSE
BEGIN
--One character remains.
--Insert the character, and exit the WHILE loop.
INSERT @retArray (idx, value)
VALUES (@idx, @sText)
SET @bcontinue = 0
END
END
END
RETURN
END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment