Jump to content


Click the link below to see the new game I'm developing!


Photo
- - - - -

Aggregate Function


6 replies to this topic

#1 priya_thomas

priya_thomas

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female
  • Location:Bangalore, India

Posted 03 October 2006 - 10:35 AM

Hi,
How will we use aggregate sql function inside proiv.
Say for eg:, I need SUM() of 1 column. Can I use SUM function inside SQL --- ENDSQL. If so, how?
Rgds Priya

#2 mglaeser

mglaeser

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Male

Posted 03 October 2006 - 12:03 PM

Include columns leading up to the one you want to SUM.
If they are ALPHA just COUNT(ALPHACOLUMN) them.

HTH
MARKIV

#3 Mike Schoen

Mike Schoen

    Expert

  • Members
  • PipPipPipPip
  • 198 posts
  • Gender:Male
  • Location:Guelph, Canada

Posted 03 October 2006 - 12:58 PM

You can use a pro-iv filedef defined as a 10-character alpha, and then on the before read logic of the file, do something like this:
SQL
SELECT TO_CHAR( SUM( COLNAME),'9999999999') AS RESULT
WHERE .....
ENDSQL
And then do a CONV(RESULT) on the no error logic

#4 andykay

andykay

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 204 posts
  • Gender:Male
  • Location:Cyberspace...looking for work

Posted 03 October 2006 - 10:14 PM

You can also place the result of the SUM directly into a variable.

SQL
BEGIN
SELECT SUM(Column_Name) INTO :#SUM FROM Table_Name WHERE...
;
ENDSQL

Good Luck,

AK
THE LIGHT AT THE END OF THE TUNNEL IS THE HEADLAMP OF THE TRAIN THAT'S ABOUT TO HIT YOU!!!

#5 Mike Schoen

Mike Schoen

    Expert

  • Members
  • PipPipPipPip
  • 198 posts
  • Gender:Male
  • Location:Guelph, Canada

Posted 03 October 2006 - 10:44 PM

SQL
BEGIN
SELECT SUM(Column_Name) INTO :#SUM FROM Table_Name WHERE...
;
ENDSQL

Wish I had known that trick earlier. (Or read the manual mabye? :unsure: )
Thats what I get for finding the first solution to a problem and then not looking further.

#6 Guest_Embedded SQL in PRO-IV is Sh!_*

Guest_Embedded SQL in PRO-IV is Sh!_*
  • Guests

Posted 04 October 2006 - 02:11 PM

[Wish I had known that trick earlier. (Or read the manual mabye? :unsure: )

No, you're doing the right thing Mike although perhaps it could be a little simpler to use a numeric key and not CONV.
Output (for example "INTO") host variables is officially unsupported in ProIV (big warning in the manual).

#7 tclulow

tclulow

    Member

  • Members
  • PipPip
  • 37 posts
  • Gender:Male
  • Location:Cambridge

Posted 13 October 2006 - 04:18 PM

We've had problems using INTO for numeric variables - they get truncated to integers.

Even this:
SQL
select numeric_column into :#VALUE where another_column = :#ANOTHER_VALUE
ENDSQL

Results in #VALUE and #ANOTHER_VALUE being truncated to integer.


I've a feeling that INTO isn't officially supported.


Tony.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Click the link below to see the new game I'm developing!