Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Calculation Problem

Author  Topic 

abhi143
Starting Member

32 Posts

Posted - 2006-04-28 : 05:36:59
I have a Field, which is of number type.

and other 4 fields also, which is number data type.

So i want to write Stored Procedure, Suppose if i enter value 21 in first field, then it store in other four field like that--

when i enter --

Enter:- 21

1st field - 5
2nd field - 5
3rd field - 5
4th field - 6


when i enter --

Enter:- 22

1st field - 5
2nd field - 5
3rd field - 6
4th field - 6

Please help me..

Thanks

Abhi

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-28 : 05:40:21
Are the values in fields 1,2 and 4 are fixed?
What do you want to insert when you enter 23?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-28 : 06:00:51
using F_TABLE_NUMBER_RANGE from here to generate the number range for testing

select *, TOTAL = FIELD_1 + FIELD_2 + FIELD_3 + FIELD_4
from
(
select NUMBER,
FIELD_1 = (NUMBER / 4),
FIELD_2 = (NUMBER / 4) + case when (NUMBER % 4) >= 3 then 1 else 0 end,
FIELD_3 = (NUMBER / 4) + case when (NUMBER % 4) >= 2 then 1 else 0 end,
FIELD_4 = (NUMBER / 4) + case when (NUMBER % 4) >= 1 then 1 else 0 end
from dbo.F_TABLE_NUMBER_RANGE(1,100)
) a


/* RESULT :
NUMBER FIELD_1 FIELD_2 FIELD_3 FIELD_4 TOTAL
----------- ----------- ----------- ----------- ----------- -----------
: : : : : :
20 5 5 5 5 20
21 5 5 5 6 21
22 5 5 6 6 22
23 5 6 6 6 23
24 6 6 6 6 24
25 6 6 6 7 25
*/




KH


Go to Top of Page
   

- Advertisement -