在Sql server Query中用decimal更新数值

时间:2021-04-03 16:35:12

I need to update the table

我需要更新表格

Query:

update um 
set ProForOccupancy = t.Occupancy 
from #Temp_UnitMix um 
join ##TempOccupency t on um.PropertyId = t.PropertyId

Table vlues are like this :

表格线是这样的:

ProFormaOccupancy(int)  Occupancy(float)
     0                 0.95
     0                 0.95
     0                 0.95
     0                 0.95

When I am trying to update nothing is updating .. Any suggestions please ..

当我试图更新时没有更新..任何建议请..

2 个解决方案

#1


1  

If you run this

如果你运行这个

SELECT CAST(0.95 AS Int)

You will see that the value of that is 0. That is what your update is doing, because of the different data types.

您将看到该值为0.这是您的更新正在执行的操作,因为数据类型不同。

Question : Should ProFormaOccupancy be a decimal or float? In that case your table definition needs to change with something the following:

问题:ProFormaOccupancy应该是小数还是浮点数?在这种情况下,您的表定义需要更改以下内容:

CREATE TABLE #Temp_UnitMix (
-- ... (your other columns here)
ProFormaOccupancy float

)

#2


0  

I've changed my temp table structure to float . it worked .. Thank you All for your replies..

我已将临时表结构更改为浮动状态。它工作..谢谢大家的回复..

#1


1  

If you run this

如果你运行这个

SELECT CAST(0.95 AS Int)

You will see that the value of that is 0. That is what your update is doing, because of the different data types.

您将看到该值为0.这是您的更新正在执行的操作,因为数据类型不同。

Question : Should ProFormaOccupancy be a decimal or float? In that case your table definition needs to change with something the following:

问题:ProFormaOccupancy应该是小数还是浮点数?在这种情况下,您的表定义需要更改以下内容:

CREATE TABLE #Temp_UnitMix (
-- ... (your other columns here)
ProFormaOccupancy float

)

#2


0  

I've changed my temp table structure to float . it worked .. Thank you All for your replies..

我已将临时表结构更改为浮动状态。它工作..谢谢大家的回复..