使用Trim,Mid和Len函数执行SQL查询时出现问题 [英] Issue in executing SQL Query with Trim, Mid and Len functions
本文介绍了使用Trim,Mid和Len函数执行SQL查询时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我编写了以下与Access数据库配合使用的查询:
Dear All,
I have written the following Query that works fine with access database:
Update MyTable Set [Column New]=IIf(Right(Trim([Column New]),1)='';'',Mid([Column New],1,Len([Column New])-1),[Column New])
但是,当我在SQL Server 2008中执行相同操作时,它说:
But, when I execute the same in SQL Server 2008, It says:
''Trim'' is not a recognized built-in function name.
如何在SQL Server中写相同的内容?
任何帮助或建议,将不胜感激.
问候,
Raj
How Do I write the same in SQL Server ?
Any help or suggestion would be greatly appreciated.
Regards,
Raj
推荐答案
SQL Server没有TRIM
函数.它具有可以一起使用的LTRIM
和RTRIM
.也没有MID
或RIGHT
.您需要使用SUBSTRING
代替 [
SQL Server does not have aTRIM
function. It hasLTRIM
andRTRIM
that you can use together. There is noMID
orRIGHT
as well. You need to useSUBSTRING
instead[^].
现在发现T-SQL没有TRIM
函数,可以使用RTRIM
和LTRIM
代替,例如RTRIM(LTRIM([Column New]))
您还可以创建自己的TRIM
函数
As you''ve now found out T-SQL doesn''t have aTRIM
function, you can useRTRIM
andLTRIM
instead, e.g.RTRIM(LTRIM([Column New]))
you can also make your ownTRIM
function
CREATE FUNCTION dbo.TRIM(@string VARCHAR(MAX)) RETURNS VARCHAR(MAX)
BEGIN
RETURN RTRIM(LTRIM(@string))
END
这篇关于使用Trim,Mid和Len函数执行SQL查询时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文