Discussion:
Deleting field in CURSOR
(too old to reply)
July Derek
2004-12-04 07:20:28 UTC
Permalink
Hi,

I create a CURSOR with different fields. How can I delete a field in
that CURSOR if all the records of that field are blank?

Thanks

Regards,
Derek
Hutch Elassaad
2004-12-04 07:25:43 UTC
Permalink
Derek,

check out the ALTER command with drop column in the help file.
the following is an extract:
ALTER TABLE TableName1 [DROP [COLUMN] FieldName3]
[SET CHECK lExpression3 [ERRORcMessageText3]] [DROP CHECK]
[ADD PRIMARY KEY eExpression3 [FOR lExpression4] TAG TagName2
[COLLATE cCollateSequence]] [DROP PRIMARY KEY]
[ADD UNIQUE eExpression4 [[FOR lExpression5] TAG TagName3
[COLLATE cCollateSequence]]] [DROP UNIQUE TAG TagName4]
[ADD FOREIGN KEY [eExpression5] [FOR lExpression6] TAG TagName4
[COLLATE cCollateSequence] REFERENCES TableName2 [TAG TagName5]]
[DROP FOREIGN KEY TAG TagName6 [SAVE]] [RENAME COLUMN FieldName4 TO
FieldName5] [NOVALIDATE]
DROP [COLUMN] FieldName3
Specifies a field to remove from the table. Removing a field from the table
also removes the field's default value setting and field validation rule.
If index key or trigger expressions reference the field, the expressions
become invalid when the field is removed. In this case, an error is not
generated when the field is removed, but the invalid index key or trigger
expressions generate errors at run time.
--
---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://mail.spaminspector.com
Post by July Derek
Hi,
I create a CURSOR with different fields. How can I delete a field in
that CURSOR if all the records of that field are blank?
Thanks
Regards,
Derek
David Frankenbach
2004-12-04 16:21:06 UTC
Permalink
Derek,

You can use the ALTER TABLE command Hutch recommends on a cursor, it is sort
of odd sytnax but it does work:

create cursor x1 ( i1 i, c1 c(10) )
insert into x1 values ( 1, 'test' )
alter table x1 drop column c1
browse
--
df - Microsoft MVP FoxPro http://www.geocities.com/df_foxpro
Post by July Derek
Hi,
I create a CURSOR with different fields. How can I delete a field in
that CURSOR if all the records of that field are blank?
julyderek@hotmail.com
2005-01-17 07:53:03 UTC
Permalink
Hi Guys,

When I use:

ALTER TABLE temp DROP COLUMN &field.....it gives me a SYNTAX error!!
Please help.
borisb
2005-01-17 09:49:28 UTC
Permalink
Post by ***@hotmail.com
Hi Guys,
ALTER TABLE temp DROP COLUMN &field.....it gives me a SYNTAX error!!
Please help.
Why You should do that?
If You create cursor via SQL Select, Just not select that field in SQL.
If You use CREATE CURSOR - create the CURSOR w/o field.
Anders Altberg
2005-01-17 12:29:39 UTC
Permalink
I tried to replicate that error:

USE H:\VFP9TESTING\customers.dbf
BROWSE LAST NOWAIT
cfield='ccustname'
ALTER table customers DROP COLUMN &cfield

No problem

-Anders
Post by borisb
Post by ***@hotmail.com
Hi Guys,
ALTER TABLE temp DROP COLUMN &field.....it gives me a SYNTAX error!!
Please help.
Why You should do that?
If You create cursor via SQL Select, Just not select that field in SQL.
If You use CREATE CURSOR - create the CURSOR w/o field.
julyderek@hotmail.com
2005-01-23 13:13:27 UTC
Permalink
Thanks guys. but is was my mistake. the variable "field" I was using
(didnt use the reserve word but just as an example) had a wrong syntax
when I used it in as &field

Regards,
Derek

David Frankenbach
2005-01-17 14:25:23 UTC
Permalink
July,

What version of VFP? What is the value of field at the time? (It's not
particularly good to use a reserved word as a memvar name field() is a
function in VFP). What is the structure of temp at the time?
--
df - Microsoft MVP FoxPro http://www.geocities.com/df_foxpro
Post by ***@hotmail.com
Hi Guys,
ALTER TABLE temp DROP COLUMN &field.....it gives me a SYNTAX error!!
Please help.
Loading...