【问题标题】:ABOUT Incorrect syntax near the keyword 'where' [duplicate]关于关键字“where”附近的语法不正确[重复]
【发布时间】:2015-08-07 11:35:07
【问题描述】:
 string sqlstr=string.Format("insert into ocs_outages(tt_id,out_date,description) values('{0}','{1}','{2}') where 'tt_id' not in (select tt_id from ocs_outages)",dr[1], Convert.ToDateTime(dr[3]).ToString("yyyy-MM-dd HH:mm:ss"), dr[2]);

错误是“关键字'where'附近的语法不正确。” 这里有什么问题?怎么工作呢?

我需要告诉用户更新完成或更新失败。 我应该怎么办 ? 感谢您阅读它。 原谅我糟糕的英语。

【问题讨论】:

标签: c# sql-server-2008 syntax where


【解决方案1】:

为什么在 WHERE CLAUSE 中使用INSERT 语句?

INSERT 用于创建新行

如果要更新任何已创建的行,请使用 UPDATE 查询。

编辑:试试这样的

IF NOT EXISTS (SELECT * FROM TABLE WHERE COLUMN = 'VALUE')
   INSERT INTO ocs_outages(tt_id,out_date,description) 
          VALUES('{0}','{1}','{2}')

【讨论】:

  • 因为这是一个新数据,但我需要检查它是否存在于数据表中。
  • 成功了!!!!谢谢。但是如何告诉用户更新成功或失败
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
  • 1970-01-01
  • 2016-06-08
  • 2013-12-16
  • 2017-11-22
  • 1970-01-01
相关资源
最近更新 更多