哪个总和sholud顶部的C#-code写出来了? [英] Which sum sholud the C#-code at the top write out?

查看:73
本文介绍了哪个总和sholud顶部的C#-code写出来了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是在aspx网站上编写的。



...

...

long sum = 0;

for(int i = 0; i< 888; i ++)

{

// GetIntFromSQL从SQL语句返回一个int -resultset with one

//行,一列

sum + = GetIntFromSQL(EXEC dbo.ObscureProcedure @i =+ i.ToString());

};

Response.Write(sum.ToString());

...

... < br $>




程序i Microsoft SQL Server服务器enligt:

创建程序dbo.ObscureProcedure

@ i int

AS

BEGIN

SELECT

CASE

什么时候@i< 260那么

COUNT(*)* @ i

ELSE

COUNT(*)* 260

END AS ObscureCount

来自

VacationGadget

WHERE

@ i< 714

END



如果您在Microsoft SQL Server Management Studio中按以下步骤驾驶它...



EXEC dbo.ObscureProcedure @i = 528



...你得到:

ObscureCount

------------

3138460



(1行(s)受影响的)



总和最后写的C#代码是什么?



i需要帮助解决这个?我不知道怎么算?我是新来的,请帮助



我的尝试:



i试图找到关于我应该如何计算这个问题但没有运气的信息。我想了解解决这个问题的公式。什么应该与什么相加并添加等等。

the following code is written in a aspx- site.

...
...
long sum = 0;
for ( int i = 0; i < 888; i++)
{
// GetIntFromSQL returns an int from an SQL-statement-resultset with one
// row, one column
sum += GetIntFromSQL("EXEC dbo.ObscureProcedure @i = "+ i.ToString());
};
Response.Write(sum.ToString());
...
...


Proceduren i Microsoft SQL Server ser ut enligt:
CREATE PROCEDURE dbo.ObscureProcedure
@i int
AS
BEGIN
SELECT
CASE
WHEN @i < 260 THEN
COUNT(*) * @i
ELSE
COUNT(*) * 260
END AS ObscureCount
FROM
VacationGadget
WHERE
@i < 714
END

if you drive it in i Microsoft SQL Server Management Studio the following procedure ...

EXEC dbo.ObscureProcedure @i = 528

... the you get :
ObscureCount
------------
3138460

(1 row(s) affected)

which sum sholud the C#-code at the top write out?

i need help solving this? i don't know how to count it ? I'm new at this, please help

What I have tried:

i have tried to find info about how i should calculate this problem but without luck. i want to understand the formula to solve this. what should i multiple with what and add and so on.

推荐答案

运行它,并找出:它将取决于您的数据,我们没有任何数据访问。
Run it, and find out: it's going to depend on your data, which we do not have any access to.


一些数学魔法的时间! :)



打破存储过程:

  • 如果 @i 大于或等于 714 ,它什么都不返回;
  • 如果 @i 大于或等于 260 ,它返回 260 × C ,其中 C VacationGadget 表中的记录数;
  • 如果 @i 小于 260 ,则返回 @i × C ;
Time for some mathematical magic! :)

Breaking the stored procedure down:
  • If @i is greater than or equal to 714, it returns nothing;
  • If @i is greater than or equal to 260, it returns 260 × C, where C is the number of records in the VacationGadget table;
  • If @i is less than 260, it returns @i × C;
  • 我们可以打折第一次迭代,因为 0 ×任何 = 0
  • 我们可能打折从 714 888 - 假设你的 GetIntFromSQL 方法在存储过程没有返回任何结果时做正确的事。
  • 对于 1 259 ,SQL的结果将是 i × C

    因此,该部分循环的总和将是:

    (来自 1 259 × C
  • 对于 260 713 ,SQL的结果将是 260 ×<$ ç$ C> C

    因此,该部分循环的总和将是( 714 - 260 )× 260 × C ;
  • We can discount the first iteration, since 0 × anything = 0.
  • We can probably discount anything from 714 to 888 - assuming your GetIntFromSQL method does the right thing when the stored procedure doesn't return any results.
  • For 1 to 259, the result from SQL will be i × C.
    Therefore, the total sum for that part of the loop will be:
    (the sum of integers from 1 to 259) × C.
  • For 260 to 713, the result from SQL will be 260 × C.
    Therefore, the total sum for that part of the loop will be (714 - 260) × 260 × C;
  • (从 1 的整数之和> 259

    = 259 × 260 ÷ 2 为什么? [ ^ ])

    = 33,670 ;
  • 714 - 260 )× 260

    = 454 × 260

    = 118,040 ;
  • (the sum of integers from 1 to 259)
    = 259 × 260 ÷ 2 (Why?[^])
    = 33,670;
  • (714 - 260) × 260
    = 454 × 260
    = 118,040;


这篇关于哪个总和sholud顶部的C#-code写出来了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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