从VBA / SQL运行更新语句到SQL服务器时,结果如下所示..
plant taskno tskstatus opened openedby title closed closedby
UK 1 closed DCR 2014-09-01 1 NULL NULL
update语句将tskstatus从OPEN移动到CLOSED。
关闭和关闭应该= TODAYS DATE和MYNAME
但是,值不会从NULL更改。
任何人都可以解释一下我需要做些什么来改变它吗?
代码在下面..(我知道代码中有更多的COLLUMNS,我删除了一些以使文本更具可读性)
sSqlClose = "UPDATE [header] SET tskstatus = 'closed' WHERE opened = '" & ValueID & "'"
sSqlClose2 = "UPDATE [header] SET closedby = 'MYNAME' WHERE 'NULL' = '" & ValueID & "'"
sSqlClose3 = "UPDATE [header] SET closed = 'CLOSED' WHERE 'NULL' = '" & ValueID & "'"
SQLconn.Execute sSqlClose
SQLconn.Execute sSqlClose2
SQLconn.Execute sSqlClose3
由于
答案 0 :(得分:0)
而不是:
SET closed = 'NULL'
尝试:
SET closed = NULL
您可以在一个语句中更新多个列:
update header
set tskstatus = 'mission accomplished'
, closedby = 'gwbush'
, closed = 'closed'
where IssueID = 'WAR-ON-TERROR-12'
答案 1 :(得分:0)
也许我不明白这个问题,但你能不能在一个声明中做这样的事情?
update header
set tskstatus = 'closed'
,closed = current_date
,closedby = 'yourname'
where tskstatus = 'open'
and opened = ?
答案 2 :(得分:0)
假设您不想一次关闭所有已打开的任务,但只有一个特定的任务,并且'ValueId'包含您的TASKNUMBER,这应该有效:
sSqlClose = "UPDATE [header] SET tskstatus = 'closed', closed = 'foo', closedby = 'bar' WHERE taskno = '" & ValueID & "'"
所有声明。
如果我的任何假设是错误的,这将无效。但是你应该提供更多信息:)