Monday, March 26, 2012

How to apply For loop here

Problem Description:

I have 5 fields in my report.
4 string type and 1 Date.
4 String type are : Unit , Periods , Grade and Demand
and 1 is Date

I would like to apply a loop which eventually sum up the value of the last field.
Before I explain it furthur I would like to add that all the string type has
multiple value in it.

Description :

I would like sum up Demand for each Grade per period per Unit.

For Example

Unit 1
Date ( monthly)1
Grade 1
Period 1 Total Demand
Period 2 Total Demand
Period 3 Total Demand

Date2
Grade 2
Period 1 Total Demand
Period 2 Total Demand
Period 3 Total Demand

I think this involves couple of For loops , Sorry but not familier with
Syntax that much.

Thanks

AbhisarDo you want to sum the field Demand which is of String type?|||Yes ,
I want to sum field demand. of string type.
so it looks like.

For loop unit ...select one unit in that string array.
then Start for loop to select the date from the Date array ( which in monthly format)
Then for loop to select the grade (string array)....
and then for each period( 3 in it ) it will show me total demand..

The actual data looks like...

Unit date grade period demand
------------------
ew 333 rrr Day 44
ew 333 rrr Eve 55
ew 333 rrr Night 22
...
...
...
ew 645 rrr Day 43
ew 645 rrr Eve 33
ew 645 rrr Night 21

Like wise
diff date .....

I would like to see

for
unit (ew) date(333) for grade(rrr)
on period (Day) total demand
(Eve) total demand
(Night) Total demand

because there are lot of person works on the same date, same unit, same grade
same three period but different demand.
I want to sum up all the demand and write a summary.

I hope I am able to explain my problem to all of u this time.

Thanks|||You can try this in the formula

numbervar eveCount;
numbervar DayCount;
whilePringtingRecords;
if {period}="Day"
DayCount:=DayCount+tonumber({Demand})
else if {period}="Eve"
EveCount:=EveCount+tonumber({Demand});|||Sorry Guys bot not working at all.

Ok , Let me reframe it to one more example.

there are 5 fields , the values in 4 of the fields are not changing at all , only in the 5th field is changing.
For example

1st field 2nd Field 3rd Field 4rth Field 5th Field

xxx rrrr tttt cccc 33
xxx rrrr tttt cccc 44
xxx rrrr tttt cccc 55

I just want to see

xxx rrrr tttt cccc 132 (total)

just in one line.

any ideas now.

Thanks|||If so, then why dont you try to write a query

Select field1,field2,field3,field4,sum(convert(numeric,field5)) from table group by
field1,field2,field3,field4
and design the report using this query

No comments:

Post a Comment