sql-server - 最近添加的表列上的 SQL“关键字附近的语法不正确”(编辑:列名是保留字)
问题描述
我的表包含以下列:
- 标识(整数)
- 错误日期(日期时间)
- 数据 nvarchar(100)
- 函数(新增列,nvarchar(100))
- 文件名(与新添加的函数相同,不过这个没问题)
我正在使用 Microsoft SQL Server 2008 R2 (SP1) - 10.50.2876.0 (X64) 2013 年 5 月 30 日 10:18:43 版权所有 (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (管理程序)
和 Microsoft SQL Server Management Studio 14.0.17277.0
我的查询是这样的:
select * from dbo.InstallationErrorLog
where data = 'Input string was not in a correct format.'
and ErrorDate > GETDATE()-90
and Function ='ProcessTblFromCSV'
查询返回错误:
消息 156,级别 15,状态 1,第 9 行关键字“功能”附近的语法不正确。
解决方案
function
是 T-SQL 中的关键字。
尝试用括号括起来:
select * from dbo.InstallationErrorLog
where data = 'Input string was not in a correct format.'
and ErrorDate > GETDATE()-90
and [Function] ='ProcessTblFromCSV'
推荐阅读
- nginx - 验证或监控与上游 grpc 的 tcp 连接数
- postgresql - kong :跨多个服务器复制数据
- spring - 用于回滚的多个 jdbcTemplate 和事务管理
- monitoring - 在 CloudWatch 中跨 ECS 任务实例聚合 codahale 指标计数
- couchdb - 同步数据库中的访问控制
- kubernetes - 什么是 Kubernetes 出口调用流程?
- ssis - SSIS 面临身份验证失败,因为远程方已关闭传输流-异常
- android - 在寻找匹配的'''时猛击意外的EOF
- shopify - 如何使用 Shopify API 创建结帐
- php - 请求缺少所需的身份验证凭据。预期要刷新的 OAuth 2 访问令牌、登录 cookie 或其他有效身份验证凭据