如何从存储过程中添加计算字段 [英] How to add calculated fields from stored procedures

查看:46
本文介绍了如何从存储过程中添加计算字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的c#窗口应用程序中,使用存储过程获取数据并绑定datagridview,但是在运行时计算出的某些字段在数据库中不可用.因此,请帮助在datagridview中添加计算字段或从存储过程中添加.

In my c# window application,get data using Stored procedure and bind datagridview but some fields calculated on runtime which is not available in database. So please help to add calculated field in datagridview or add from stored procedure.

推荐答案

您可以在sp查询中创建由2个或更多列组成的字段在您选择的
you can create a field in your sp query that is the result of 2 or more columns in your select like
select artno, artname, nrOrdered, price, (nrOrdered * price) [OrderlinePriceTotalValue]
from TableWithGoods


,您可以在查询中创建计算列并为其指定别名,然后您将能够像常规列一样访问这些列.
You can create calculated columns in your query and give them an alias, and then you will be able to access these columns like regular columns.
SELECT Quantity, UnitRate, Tax, ((Quantity * UnitRate) + Tax) AS LineAmount
FROM OrderDetails
WHERE OrderID = @OrderID


这篇关于如何从存储过程中添加计算字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆