调用“ExecuteNonQuery”的异常

时间:2015-06-01 13:27:16

标签: sql-server powershell exception

当我尝试通过PowerShell在数据库中插入新数据时,它可以正常工作。

但是,如果数据已经存在于数据库中,则会出现异常。

有人有类似的问题,Catch exception calling "ExecuteNonQuery",但我相信我在PowerShell代码中使用了正确的SQL语句,我说library (dplyr) y.max <- data.plot %>% group_by(x) %>% summarize(s = sum(value)) y.max <- max(y.max$s) p + geom_step(aes(x = x - 0.5, ymax = value), position = "stack") + annotate('segment', x = min(data.plot$x) - 0.5, xend = min(data.plot$x) - 0.5, y = 0, yend = y.max) + annotate('segment', x = min(data.plot$x) - 0.5, xend = max(data.plot$x) - 0.5, y = 0, yend = 0)

SELECT 1

例外

$SQL_insert = "BEGIN
              IF NOT EXISTS (SELECT 1
                             FROM [dbo].[Group_Stats]
                             WHERE Date_of_Record = CAST(GETDATE() AS DATE)
                             AND [Group] = '$group')
              BEGIN
                  INSERT INTO [dbo].[Group_Stats] ([Date_of_Record], [Group], [Windows_SEP_11],[Mac_SEP_11],[Windows_SEP_12],[Mac_SEP_12])
                  VALUES (CAST(GETDATE() AS DATE), REPLACE ('$group', 'My Company\', ''), $win_sep_11, $mac_sep_11, $win_sep_12, $mac_sep_12)
              END
          END"

这是数据库

enter image description here

由于

1 个答案:

答案 0 :(得分:1)

您正在查询未修剪的群组名称,但在插入时,请致电REPLACE()以关闭$group“我的公司”。您应首先修剪$group,然后在不调用REPLACE()的情况下查询和插入。

相关问题