从.NET中的SQL Calculation子句读取数据 [英] Read data from sql compute clause in .NET

查看:38
本文介绍了从.NET中的SQL Calculation子句读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从这样的sql语句中获取.NET中的计算值:

How can I get computed values in .NET from a sql statement like this:

select name, earning from customer
compute min(earning), max(earning)



如果执行此insinde Management Studio,则会从客户那里获得行,并获得带有最小值和最大值的割线集.

但是使用.NET中的DataReader,我只能从客户那里获得一个带有行的表.

更新:
我认为,从一个查询中有2个结果集.但是我不知道如何访问第二个.



If I execute this insinde management studio, I get the rows from customer and a secound set with the min and max values.

But with a DataReader in .NET, I can get only a table with rows from customer.

Update:
I think, there are 2 result sets from one query. But I don''t know how to access to the second.

推荐答案

如果您只有sql的计算值.

If you had just the computed values from sql.

using (SqlConnection conn = new SqlConnection(@"YourDatabaseInfo"))
      {
        conn.Open();
        SqlDataReader myReader = null;
        SqlCommand cmd = new SqlCommand("select name, earning from customer compute min(earning) as [MinEarned], max(earning) as [MaxEarned]", conn);
        myReader = cmd.ExecuteReader();
        while (myReader.Read())
        {
int MinEarned = Convert.ToInt32(myReader["MinEarned"]);
int ManEarned= Convert.ToInt32(myReader["MaxEarned"]);
        }
mtReader.close();
conn.close();
      }




我认为此查询将为您提供帮助.


Hi

I think this query will help you..


select name, earning,(select min(earning) from customer) as MinEarning,

(select max(earning) from customer) as MaxEarning from customer   where earning in
( (select min(earning) from customer) ,

(select max(earning) from customer))




阿斯瓦西·纳拉扬(Awathi Narayan)




Aswathi Narayan


这篇关于从.NET中的SQL Calculation子句读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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