如何计算访问查询中SQL Server ntext(即备忘录)字段中的字符数? [英] How do I count the number of characters in SQL server ntext (i.e. memo) field in an access query?

查看:63
本文介绍了如何计算访问查询中SQL Server ntext(即备忘录)字段中的字符数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个访问查询以计算链接的SQL Server表中ntext字段中的字符.

I want to write an access query to count the characters in an ntext field in a linked SQL server table.

在SQL Server中,我只使用以下命令(在访问中不起作用):

In SQL server, I would just use this command (which wont work in access):

 select datalength(nTextFieldName) //this command works on sql server but not in access 

在访问中,我只能找到len命令,该命令不适用于ntext字段:

In access, I can only find the len command, which wont work on ntext fields:

select len(nTextFieldName) // access says nText is not a valid argument to this function.

谷歌搜索,我发现一堆帖子说要使用len,这给了我一个错误.

Googling around, I've found a bunch of posts saying to use len, which is giving me an error.

命令是什么?

推荐答案

ntext类型不适用于LEN.不建议使用此特定类型以及其他一些类型:

ntext type doesn't work with LEN. This specific type as well as a few others are deprecated:

ntext, text, and image data types will be removed in a future version of Microsoft SQL 
Server. Avoid using these data types in new development work, and plan to modify applications 
that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. For more 
information, see Using Large-Value Data Types.

处理此问题的最佳方法是将数据类型转换/转换为可以工作的数据类型,例如varchar(max)/nvarchar(max),然后再获取LEN.

The best way to handle this is to convert/cast the datatype to one that works such as varchar(max)/nvarchar(max) and only then get the LEN.

SELECT LEN(CAST(nTextFieldName As nvarchar(max)))

这篇关于如何计算访问查询中SQL Server ntext(即备忘录)字段中的字符数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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