使用Trim,Mid和Len函数执行SQL查询时出现问题 [英] Issue in executing SQL Query with Trim, Mid and Len functions

查看:340
本文介绍了使用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 a TRIM function. It has LTRIM and RTRIM that you can use together. There is no MID or RIGHT as well. You need to use SUBSTRING instead[^].


现在发现T-SQL没有TRIM函数,可以使用RTRIMLTRIM代替,例如RTRIM(LTRIM([Column New]))

您还可以创建自己的TRIM函数
As you''ve now found out T-SQL doesn''t have a TRIM function, you can use RTRIM and LTRIM instead, e.g. RTRIM(LTRIM([Column New]))

you can also make your own TRIM function
CREATE FUNCTION dbo.TRIM(@string VARCHAR(MAX)) RETURNS VARCHAR(MAX)
BEGIN
    RETURN RTRIM(LTRIM(@string))
END


这篇关于使用Trim,Mid和Len函数执行SQL查询时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆