本文介绍了将查询结果保存在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我使用的查询.这里根据 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") }更多推荐
将查询结果保存在变量中
发布评论