Sql Query抛出标识符太长。最大长度为128

时间:2015-02-17 00:21:02

标签: sql sql-server sql-update

我正在处理一个简单的更新查询,我在执行查询时看到以下错误。我非常清楚,这根本不应该是一个长度问题。可能是什么问题。

错误:

  

以标识符开头的标识符太长。最大长度为128

我的查询:

update dbo.DataSettings set 
Query ="/Details?$filter=(Status ne 'yes' and Status ne 'ok')&$expand=name,Address/street,phone/mobile&$orderby=details/Id desc"
where id=5

3 个答案:

答案 0 :(得分:14)

使用单引号并使用两个单引号转义文本中的引号:

update dbo.DataSettings set
set Query= '/Details?$filter=(Status ne ''yes'' and Status ne ''ok'')&$expand=name,Address/street,phone/mobile&$orderby=details/Id desc'
where id=5

答案 1 :(得分:1)

您应该使用单引号'(并使用反斜杠\转义字符串中的那些引号),因为现在您要为标识符分配Query(在这种情况下,列如果它甚至是标识符的正确大小,您可能会收到类似无效列名的错误:

UPDATE dbo.DataSettings
SET Query ='/Details?$filter=(Status ne \'yes\' and Status ne \'ok\')&$expand=name,Address/street,phone/mobile&$orderby=details/Id desc'
WHERE id = 5

答案 2 :(得分:0)

仅供参考 我曾经遇到过同样的问题,以上答案无法解决我的问题。然后我意识到用于保留链接服务器的全限定名称的变量的长度不够,我将变量的长度更改为等于全限定名的长度,我的查询效果很好。有时候就这么简单