' - '附近的语法不正确。 [英] Incorrect syntax near '-'.

查看:43
本文介绍了' - '附近的语法不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行sql查询,但我继续收到此错误' - '附近的语法不正确。



此sql用于检索范围日期的数据。



这里是我的sql



  ALTER   PROCEDURE  [dbo]。[viewMaterialByDate] 
@ fromDate date
@ toDate date
AS
选择 MaterialID,材料,主题 FROM StudyMaterial,主题
WHERE Topic.TopicID = StudyMaterial.TopicID
[日期]> = @ fromDate [日期]< = @ toDate

解决方案

尝试以下操作,因为您可能忘记在参数中添加大括号:



  ALTER   PROCEDURE  [dbo]。[viewMaterialByDate] 
@ fromDate date
< span class =code-sdkkeyword> @ toDate date
AS
选择 MaterialID,材料,主题 FROM StudyMaterial,主题
WHERE Topic.TopicID = StudyMaterial.TopicID
[日期]> = @ fromDate [日期]< = @ TODATE


硅如果您正处于ALTER PROCEDURE的阶段,我认为SP是数据库的一部分(奇怪的是,您将SP命名为视图)。



即说,它必须是导致错误的数据条目 - 你有一个失败的条目样本吗?您是否尝试使用硬编码日期作为范围,或者这是程序循环(这需要您查看数据源)的结果?



另一个想法:为什么不在StudyMaterial和Topic表之间进行INNER JOIN,因为您需要匹配所有查询返回值?




问题可能在于您传递的日期值,因为查询中没有其他内容可能导致错误。尝试为同一个查询提供硬编码值以进行测试,然后运行它;如果它有效,那么显然是日期参数的问题。


m executing sql query but i keep on getting this error "Incorrect syntax near '-'."

this sql is for retriving data of a range date.

here is my sql

ALTER PROCEDURE [dbo].[viewMaterialByDate]
@fromDate date,
@toDate date
AS
Select MaterialID,Material,Topic  FROM StudyMaterial,Topic
WHERE Topic.TopicID= StudyMaterial.TopicID and 
 [Date] >=@fromDate and [Date] <= @toDate

解决方案

try the below as you might forgot to add braces to the parameters:

ALTER PROCEDURE [dbo].[viewMaterialByDate]
(@fromDate date,
@toDate date)
AS
Select MaterialID,Material,Topic  FROM StudyMaterial,Topic
WHERE Topic.TopicID= StudyMaterial.TopicID and
 [Date] >=@fromDate and [Date] <= @toDate


Since you're at the stage of an ALTER PROCEDURE, I presume the SP is part of the database (odd that you name a SP a view).

That being said, it must be the data entry that is causing the error - do you have a sample of an entry that fails? Have you tried this with hard-coded dates as the range or is this the result of something like a program loop (which would require you looking into your data feed)?

Another thought: why not an INNER JOIN between StudyMaterial and Topic tables since you require a match for all of your query return values?


The issue may be with the date values which you are passing because there is nothing else in your query which may cause an error. Try giving hard-coded values for testing to the same query and then run it; if it works then it is obviously the issue with date parameters.


这篇关于' - '附近的语法不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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