Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Complicated SQL - can we make it?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00437328
Message ID:
00438266
Views:
17
Nadya,

In fact you then have the months cursor.
It is not difficult then to create the quater and year cursor too.

The code i send to you earlier will then also fill in the months that are not in the the table.
For example if you haven't sold anything in october and your range is from september to november then you'll see a result for october too now
e.g.:
september sales = 200
november sales = 100
will give
september: n=1 totsales = 200
october : n=1 totsales = 200
september: n=2 totsales = 300

Hope it helps you,

Ko Wisse

PS. The yearmonth field you also create here is not directly needed.
It is created in the sql too.
for the quaters yearqtr is created, and for the years only the year is needed.

>>
LOCAL dIncDate, aDateRange[1,2], cDateToStick, cMonthPart
>>SELECT MIN(DATE(val(cYear),val(cMonth),1)) as dmin, ;
>>       MAX(DATE(val(cYear),val(cMonth),1)) as dMax ;
>>  FROM InputTable ;
>>  INTO ARRAY aDateRange  && Save min and max 1st of month in array
>>
>>SELECT 0
>>CREATE CURSOR tblPeriods ( cYearMonth C(6), ;
>>                           cYear C(4), ;
>>                           cMonth C(2), ;
>>                           cQuarter C(2) )
>>
>>dIncDate = aDateRange[1,1]              && Start at first month
>>DO WHILE dIncDate <= aDateRange[1,2]    && For each month through the last
>>   cDateToStick = DTOS(dIncDate)        && Convert to YYYYMMDD
>>   cMonthPart = SUBST(cDateToStick,5,2) && Snag MM
>>
>>   INSERT INTO tblPeriods VALUES ( left(cDateToStick,6), ;
>>                                   left(cDateToStick,4), ;
>>                                   cMonthPart, ;
>>                                   'Q' + TRANSFORM(CEILING(VAL(cMonthPart)/3)) )
>>
>>   dIncDate = GOMONTH(dIncDate,1)       && next month
>>ENDDO
>
>
>Great! Much more elegant and simple, than my idea. Thanks a lot, I'll use it.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform