哪个总和sholud顶部的C#-code写出来了? [英] Which sum sholud the C#-code at the top write out?
问题描述
以下代码是在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 to714
, it returns nothing;- If
@i
is greater than or equal to260
, it returns260
×C
, whereC
is the number of records in theVacationGadget
table;- If
@i
is less than260
, it returns@i
×C
;
- 我们可以打折第一次迭代,因为
0
×任何 =0
。 - 我们可能打折从
714
到888
- 假设你的GetIntFromSQL
方法在存储过程没有返回任何结果时做正确的事。 - 对于
1
到259
,SQL的结果将是i
×C
。
因此,该部分循环的总和将是:
(来自1 $ c的整数之和$ c>到
×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
to888
- assuming yourGetIntFromSQL
method does the right thing when the stored procedure doesn't return any results. - For
1
to259
, the result from SQL will bei
×C
.
Therefore, the total sum for that part of the loop will be:
(the sum of integers from1
to259
) ×C
. - For
260
to713
, the result from SQL will be260
×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
to259
)
=259
×260
÷2
(Why?[^])
=33,670
; - (
714
-260
) ×260
=454
×260
=118,040
;
这篇关于哪个总和sholud顶部的C#-code写出来了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!