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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error (Create Cursor) 3

Status
Not open for further replies.

Rock4J

Programmer
Jan 14, 2013
94
MY
Hi friends,

I'm trying to write the following code but, there was syntax error when I test it.

Code:
Create cursor C:\Work\Payroll\WHAnalysis.dbf free;
	(Name C(50),;
	Empno C(10),;
	Dworkn N(8),;
	Hoursn N(8),;
	Dwork N(8),;
	Hours N(8),;
	DiffHrs N(8))

Any comments is appreciated. Thank you! :)

Regards,
Rocky
 
|you can't have a path when create a cursor. The cursor is an temporary table created always in TEMP folder.
After you close that cursor it will be deleted.

Borislav Borissov
VFP9 SP2, SQL Server
 
Change it to :

Create cursor WHAnalysis ;
(Name C(50),;
Empno C(10),;
Dworkn N(8),;
Hoursn N(8),;
Dwork N(8),;
Hours N(8),;
DiffHrs N(8))


 
Thanks guys! I really appreciates that.. ^_^

Regards,
Rocky
 
Also notice:

A Cursor can have most features of DBC tables, that is long names, default values and some more. What you can't define is a primary index, but of course you can still apply a CANDIDATE Index, like with free tables. Also cursors can participate in transactions by default, not just after being made transactable, like free tables need to. Overall Cursors are more like database tables than like free tables, which is a big advantage additional to the automatic cleanup.

Bye, Olaf.
 
Hi again,

I have onother problem here, please help me to check this code.

Code:
Create Cursor WHAnalysis;
	(Name C(50),;
	Empno C(10),;
	Dworkn N(8),;
	Hoursn N(8),;
	Dwork N(8),;
	Hours N(8),;
	mDiff N(8))

Select Name,Empno,Dwork,Dworkn from Emplpay into cursor WHAnalysis

Select WHAnalysis
Replace Hours with Dwork*3
Replace Hoursn with Dworkn*3
Replace mDiff with Hoursn-Hours

Select  WHAnalysis
mFrx = "rptwhour"
Push Menu _msysmenu
Report form &mFrx noconsole preview
Pop Menu _msysmenu

What is the correct way to write this code? I get error on Hours, Hoursn & mDiff.

Regards,
Rocky
 
You can't select into a cursor you created with Create Cursor this way, because SELECT .. INTO CURSOR creates that cursor, even if it already exists, it will be closed, deleted and then recreated. So it won't have the fields you replace in, also it's not READWRITE.

If you want to use your self defined cursor as the target of your SQL, you'll need an INSERT:

Insert Into WHAnalysis (Name,Empno,Dwork,Dworkn) Select Name,Empno,Dwork,Dworkn from Emplay

What you can also do is this instead:

Select Name,Empno,Dworkn, Cast(0 as N(8)) as Hoursn, Dwork, Cast(0 as N(8)) as Hours, Cast(0 as N(8)) as mDiff from Emplay into Cursor WHAnalysis READWRITE

Or you could do
SELECT WHAnalysis
APPEND FROM DBF("Emplay")

But:
SELECT ... INTO ARRAY creates an array,
SELECT ... INTO TABLE creates a table,
SELECT ... INTO CURSOR creates a cursor.

It does not select into an already existing array, table or cursor. Please refer to help.

Bye, Olaf.
 
I see... Thank you very much Olaf! I'll try first.. :)

Regards,
Rocky
 
Also: You can directly compute Hours = Dwork*3 etc inside the SQL:

Select Name,Empno,Dworkn, Dworkn*3 as Hoursn, Dwork, Dwork*3 as Hours, Dworkn*3-Dwork*3 as mDiff from Emplay into Cursor WHAnalysis READWRITE

Bye, Olaf.
 
...You can even do

Select Empno, Name, Sum(Dwork*3) as TotalHours, Sum(Dworkn*3) as TotalHoursn, Sum((Dworkn-Dwork)*3) as TotalDiff From Emplay Group By 1,2 Into Cursor WHTotals

You don't need to go through intermediate steps to aggregate data into statistics.

Bye, Olaf.
 
I have tried this code:

Code:
Select Name,Empno,Dworkn,Cast(0 as N(8)) as Hoursn, Dwork, Cast(0 as N(8)) as Hours, Cast(0 as N(8)) as mDiff from Emplay into Cursor WHAnalysis READWRITE

but it return this error: Function name is missing ).

Regards,
Rocky
 
At which foxpro version are you? Do you even have CAST at hand?

The last thing I gave you should even work in VFP6, maybe VFP5:
Select Empno, Name, Sum(Dwork*3) as TotalHours, Sum(Dworkn*3) as TotalHoursn, Sum((Dworkn-Dwork)*3) as TotalDiff From Emplay Group By 1,2 Into Cursor WHTotals

CAST only is available in VFP9. I see no missing paranhesis.

Bye, Olaf.
 
I'm using VFP6, I have just tried your last code but it return: Command contains unrecognized phrase/keyword.

Regards,
Rocky
 
Sorry, I can't install VFP6 just to see what exactly isn't working.
Start simpler and see what exactly fails, eg start with

Select Empno, Name, Sum(Dwork) as TotalDwork, Sum(Dworkn) as TotalDworkn From Emplay Group By 1,2 Into Cursor WHTotals

Bye, Olaf.
 
The Emplpay table is located in the [my_project_path]\Data
could it be the problem? :)

Regards,
Rocky
 
If VFP wouldn't find the Emplay DBF, it would react to that by a file open dialog, not with that error. My assumption is you can't use expressins within SUM() in VFP6. You get used to many things once you upgrade, and you never know what's not possible with earlier versions.

I can already tell you that the syntac with INSERT INTO WHAnalysis .. SELECT ... FROM Emplay will only work in VFP9. You miss a lot of god stuff, plus VFP6 was very buggy, even with SP5 applied. Just that high number of service packs tells you how buggy the initial version was.

Bye, Olaf.
 
No problem Olaf, take your time.. :)

I even tried this way:

Select Name,Empno from Emplpay Group By 1,2 Into Cursor WHAnalysis READWRITE

but still the same error appears.

Regards,
Rocky
 
Ok, I will keep on trying first. Thanks Olaf.. :)

Regards,
Rocky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top