如何添加两个字段值并将它们插入单个列?

时间:2013-03-06 09:14:29

标签: sql sql-server crystal-reports

我有一张桌子:

MTCN       Number        RecPrincipalAmount        TotalCharges
123        APK123            506.21                   258.22

现在我想添加RecPrincipalAmountTotalCharges并将其插入PrincipalAmount

我想要这个:

MTCN       Number        PrincipalAmount        
123        APK123            764.43

我想在Crystal Reports中显示所有这些数据。

4 个答案:

答案 0 :(得分:1)

select MTCN,
       Number,
       RecPrincipalAmount+TotalCharges as PrincipalAmount
from YourTable

您可以在添加之前将varchar转换为float

select MTCN,
       Number,
       cast(RecPrincipalAmount as float)+cast(TotalCharges as float) as PrincipalAmount
from YourTable

money如果更合适。

select MTCN,
       Number,
       cast(RecPrincipalAmount as money)+cast(TotalCharges as money) as PrincipalAmount
from YourTable

答案 1 :(得分:0)

尝试使用它。

SELECT 
   MTCN,
   Number,
   CONVERT(FLOAT, RecPrincipalAmount) + CONVERT(FLOAT, TotalCharges) PrincipalAmount
FROM TableName

答案 2 :(得分:0)

使用公式字段:

//{@Principal}
{table.RecPrincipalAmount} + {table.TotalCharges}

答案 3 :(得分:-1)

SELECT SUM(RecPrincipalAmount + TotalCharges ) as "You Column"
FROM Your_Table;