在SQL查询或UI代码中计算金额(数量*价格)(Calculate Amount (Qty * Price) in SQL query or UI Code)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
在SQL查询或UI代码中计算金额(数量*价格)(Calculate Amount (Qty * Price) in SQL query or UI Code)

在下面的查询中,我只是获取项目详细信息及其数量和速率(根据某些业务逻辑计算的数量和速率,以便使用子查询或聚合)。

SELECT ItemID, ItemName, (... ... ) AS ItemQty, (.... .... ) AS ItemPrice FROM ....

现在我需要在Amount (即ItemQty * ItemPrice )的网格中列出这些细节。

Sample Output ------ ItemId ItemName ItemQty ItemPrice Amount 1 ABC 10.0 22.5 225.0 2 PQR 12.35 156.5 1932.775

我有两个选项来计算Amount ( ItemQty * ItemPrice )

计算sql查询本身的数量

再次使用整个子查询来乘以值或外部选择查询来计算相同

使用UI /代码部分计算ItemQty * ItemPrice,同时将数据绑定到网格。

在这个我可以遵循哪一个?

In the below query, i just fetch the Item details with its qty and rate (qty and rates ate calculated based on some business logic, so that using sub queries or aggregates).

SELECT ItemID, ItemName, (... ... ) AS ItemQty, (.... .... ) AS ItemPrice FROM ....

Now i need to list this details in a grid with Amount (ie ItemQty * ItemPrice).

Sample Output ------ ItemId ItemName ItemQty ItemPrice Amount 1 ABC 10.0 22.5 225.0 2 PQR 12.35 156.5 1932.775

I have two options to calculate Amount (ItemQty * ItemPrice)

Calculate the amount in sql query itself

using the entire sub queries again to multiply the values or an outer select query to calculate the same

use the UI/code part to calculate the ItemQty * ItemPrice while binding the data to grid.

In this which one i can follow?

最满意答案

您应该通过在UI中进行逻辑来隔离逻辑。

SQL代码比C#代码更快吗?

此链接很好地解释了您的问题。

希望这可以帮助!

You should isolate the logic by doing it in UI.

Is SQL code faster than C# code?

This link explains well for your question.

Hope this helps!

更多推荐

本文发布于:2023-04-21 18:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c267914e5200742f29b41a0af1a17c3e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:金额   数量   代码   价格   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!