Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a more elegant solution SQL
Message
From
27/07/2007 12:05:00
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
27/07/2007 11:44:08
Bill Drew
Independent Consultant
Chicago, Illinois, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01244138
Message ID:
01244156
Views:
14
>I'm looking to count the number of incidents various ranges of months.
>
>Can the following query be done without the second procedural step -- purely in SQL?
>
>
>*******************************
>PROCEDURE GetViosInRange
>*******************************
>LPARAMETERS tcVioCat,tnLowMonths,tnHiMonths,tnLowBound,tnHiBound
>LOCAL lnRetVal
>SELECT * FROM WCDRVA ;
>WHERE mvrcat = tcVioCat ;
>AND BETWEEN(monthsago,tnLowMonths,tnHiMonths) ;
>AND drvseq = this.drivernum;
>INTO cursor thesevios
>lnRetVal = 0
>IF tnlowbound > 0
>   SKIP tnlowbound-1
>   SCAN WHILE RECNO() <= tnhibound
>     lnretval = lnretval + 1
>   ENDSCAN
>endi
>RETURN lnRetVal
>
IF m.tnlowbound > 0
 local array arrCount[1]
 SELECT cnt(*) FROM WCDRVA ;
  WHERE mvrcat = tcVioCat ;
  AND BETWEEN(monthsago,tnLowMonths,tnHiMonths) ;
  AND drvseq = this.drivernum;
  INTO array arrCount
 return iif( m.tnLowBound <= arrCount, min(m.tnHighBound, arrCount)-m.tnLowBound+1, 0)
else
 return 0
endif
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform