将查询结果保存在变量中

编程入门 行业动态 更新时间:2024-10-24 12:32:57
本文介绍了将查询结果保存在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面是我使用的查询.这里根据 status 列中的数据得到 weightagepercentage 列的总和.

Below is the query am using. Here am getting the sum of weightagepercentage column depending on the data in status column.

Status|WeightPer ___________________ P | 2 F | 3 F | 1 P | 1 SELECT Status, SUM(WeightagePercent) AS Final FROM ProoferTbl GROUP BY Status

决赛有

F=4 P=3

我需要将结果保存在 2 个变量中通过和失败的值并比较它们的最大值.是否有可能这样做,或者我必须改变什么?

I need to save the result in 2 variables Pass and fail with the values and compare them for greatest. Is it possible to do so or do I have to change something?

推荐答案

SqlConnection con = new SqlConnection("..."); string strSQL = "SELECT SUM(case when Status = 'P' then WeightagePercent else 0 end) as passed, " + " SUM(case when Status = 'F' then WeightagePercent else 0 end) as failed " + "FROM ProoferTbl2 " + "GROUP BY Status"; SqlCommand cmd = new SqlCommand(strSQL, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); int passed = 0, failed = 0; while (reader.Read()) { passed = (int) reader["passed"]; failed = (int) reader["failed"]; } reader.Close(); con.Close(); If(passed > failed) { Messagebox.show("Pass") }

更多推荐

将查询结果保存在变量中

本文发布于:2023-11-24 03:25:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623799.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:查询结果   变量

发布评论

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

>www.elefans.com

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