我想要做類似如下(在SQL Server):我可以使用更新來增加SQL記錄中的值嗎?
update person set numItems += @num, today = @updateDate where id = @id
我知道了「一個numItems + = @num」是不正確的語法,我怎麼寫的那一部分?
我想要做類似如下(在SQL Server):我可以使用更新來增加SQL記錄中的值嗎?
update person set numItems += @num, today = @updateDate where id = @id
我知道了「一個numItems + = @num」是不正確的語法,我怎麼寫的那一部分?
SQL Server不具有+=
符號,所以才展開全面
update person set numItems = numItems + @num, today = @updateDate where id = @id
某些數據庫做支撐+=
。但是,下面是標準的SQL:
update person
set numItems = numItems + @num,
today = @updateDate
where id = @id;
「*有些數據庫支持+ = *」 - 真的嗎?哪一個? – 2014-09-19 21:36:06
@a_horse_with_no_name SQL Server 2008+ – 2014-09-19 22:12:42
由於SQL Server 2008中,*添加的Equals *運營商和親屬已經由SQL Server 2008的支持:http://msdn.microsoft.com/en-us/library /cc627392(v=sql.100).aspx – 2014-09-19 21:55:51