开发者

T-SQL trim not working - let spaces on the result

I have a trim function that apply ltrim and rtrim

CREATE FUNCTION dbo.TRIM(@string VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@string))
END
GO

I do the following query:

SELECT distinct dbo.trim([subject]) as subject
FROM [DISTR]

The result has rows开发者_开发技巧 like:

"A"
"A  "
"B"
...

I thought that thoose chars maybe weren't spaces but when I got the ascii code, it returns 32 which is the code for space.

My only guess is that I had to change the collaction of the database to: SQL_Latin1_General_CP1_CI_AI

Can that be the problem? Any ideas? Thanks


Maybe your field contains more than spaces. Remember than " " could be a space, tab, and many other "blank" chars. It's possible to match it using ASCII or building a CLR implementation of trim that uses regular expressions

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜