检查连接到 varchar(max) 是否会超出最大允许字符数

2021-09-10 00:00:00 tsql sql-server varchar

我正在尝试将一个 ID 列表连接到一个 varchar(max) 中,以传递到一个用于批量更新数据的 openquery.

I am trying to concatenate a list of IDs into a varchar(max) to pass into an openquery for a bulk update of data.

我的问题是,除了将字符串与数字进行比较之外,是否有一种简单的方法可以查看字符串是否超出了 varchar(max) 可以处理的长度?

My question is, is there an easy way to see if a string is beyond the length a varchar(max) can handle aside from comparing it to the number?

我见过这个:varchar(max) 中有多少个字符它指定了 varchar(max) 的确切长度,但我希望有一种比将长度与静态数值进行比较更简单的方法.

I have seen this: How many characters in varchar(max) which specifies the exact length of a varchar(max), but I was hoping for a simpler method than comparing length to a static numeric value.

如果需要更多信息,请告诉我.

Please let me know if any more information is needed.

推荐答案

varchar(max) 的最大长度是 2GB 但是 openquery 只需要 8K 根据 在线书籍

The max length of varchar(max) is 2GB however openquery only takes 8K according to Books On Line

OPENQUERY (linked_server ,'查询')参数链接服务器是表示链接服务器名称的标识符.

OPENQUERY (linked_server ,'query') Arguments linked_server Is an identifier representing the name of the linked server.

'查询'是在链接服务器中执行的查询字符串.字符串的最大长度为 8 KB.

'query' Is the query string executed in the linked server. The maximum length of the string is 8 KB.

相关文章