Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP6.0 Question

Status
Not open for further replies.

rstum2005

Programmer
Jun 9, 2005
117
US
I Run this Query in VFP6.0 And It Returns the Two Columns but the Radius Column needs to be a whole number.

SELECT DISTINCT RADIUS,count(*)AS QUANTITY FROM rstemp group by RADIUS order by RADIUS

So..

I tried this and it give me an error.

SELECT DISTINCT CAST(RADIUS AS NUMERIC(10,0)),count(*)AS QUANTITY FROM rstemp group by CAST(RADIUS AS NUMERIC(10,0)) order by CAST(RADIUS AS NUMERIC(10,0))

Can anyone help?
 
Also, I ran that and it did work but the distinct function stopped working?
 

rstum2005,

Yes, ROUND() function didn't go anywhere, and you don't need DISTINCT keyword when you use GROUP BY clause. Grouping will make it distinct. Also, when you want to group by a field created from a calculated expression, group by field number, not name or expression.

Try this:

SELECT ROUND(RADIUS,0), COUNT(*) AS QUANTITY ;
FROM rstemp ;
GROUP BY 1 ;
ORDER BY 1
 
Do you know how to make it so you can run the same query in both SQL and VFP6?


Select ROUND(Radius,0) AS RADIUS, count(*) AS QUANTITY FROM rstemp group by ROUND(Radius,0) order by ROUND(Radius,0)

This runs in SQL but not in VFP.
And The Query you posted runs in VFP but not in SQL.
 


Rstum,

Is The Round Function in VFP9 Also?

Yes, it's in every version since Foxbase and earlier.

Do you know how to make it so you can run the same query in both SQL and VFP6?

What do you mean by that? The SELECT command is is SQL.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 

Mike, I guess, rstum2005 needs it to run on both, VFP native tables AND SQL Server back end. That's why I said that I mostly work in VFP - meaning native tables.

The way I understood it, with an expression in the GROUP BY clause it doesn't work on VFP native table, and with GROUPing BY the number of the field it doesn't work in SQL Server.
 

Stella,

I guess, rstum2005 needs it to run on both, VFP native tables AND SQL Server back end.

I didn't notice any reference to SQL Server in particular. But you might be right.

with GROUPing BY the number of the field it doesn't work in SQL Server.

That's correct. You have to specify the name of the field, unlike in VFP. It's caught me out more than once.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top