Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 基于日期时间将列更新为整数_Sql_Sql Server 2008 - Fatal编程技术网

Sql 基于日期时间将列更新为整数

Sql 基于日期时间将列更新为整数,sql,sql-server-2008,Sql,Sql Server 2008,我试图对一个sql表进行大规模更新,但我不理解逻辑等价物。在伪代码中,我想做的是: UPDATE mytable SET mycolumn = (pull down the datetime from mycolumn2. if the year of that datetime is not equal to 2013, then mycolumn = 24. if the year is 2013, then mycolumn = 24 - number of months in that

我试图对一个sql表进行大规模更新,但我不理解逻辑等价物。在伪代码中,我想做的是:

UPDATE mytable
SET mycolumn = (pull down the datetime from mycolumn2. if the year of that datetime is not equal to 2013, then mycolumn = 24. if the year is 2013, then mycolumn = 24 - number of months in that datetime)
我真的不知道从哪里开始在SQL中实现这种逻辑。有人能给我一些建议或指导吗

谢谢

根据需要调整RDBMS的日期语法

UPDATE mytable
SET mycolumn = CASE WHEN YEAR(mycolumn2) <> 2013 
                    THEN 24
                    WHEN YEAR(mycolumn2) = 2013 
                    THEN 24 - mycolumn
                END
根据需要调整RDBMS的日期语法。

更新mytable
UPDATE mytable
SET mycolumn = CASE WHEN YEAR(mycolumn2) <> 2013 
                    THEN 24
                    WHEN YEAR(mycolumn2) = 2013 
                    THEN 24 - mycolumn
                END
设置mycolumn=2013年(mycolumn 2)时的情况 那么24 年份(菌落2)=2013年 然后是24-菌柱 结束
更新我的表格
设置mycolumn=2013年(mycolumn 2)时的情况
那么24
年份(菌落2)=2013年
然后是24-菌柱
结束
使用
简单案例
陈述:

update mytable
set mycolumn = 24 - case year(mycolumn2) 
                        when 2013 then  month(mycolumn2)
                        else 0 
                    end
使用
简单案例
陈述:

update mytable
set mycolumn = 24 - case year(mycolumn2) 
                        when 2013 then  month(mycolumn2)
                        else 0 
                    end

SQL只是结构化查询语言-一种被许多数据库系统使用的语言,但不是一种数据库产品。。。很多东西都是特定于供应商的-因此我们确实需要知道您使用的是什么数据库系统(以及哪个版本)…@marc_s我使用的是Microsoft SQL Server 2008。。sorrySQL只是结构化查询语言-一种被许多数据库系统使用的语言,但不是一种数据库产品。。。很多东西都是特定于供应商的-因此我们确实需要知道您使用的是什么数据库系统(以及哪个版本)…@marc_s我使用的是Microsoft SQL Server 2008。。很抱歉