Create field if not exist

  • Thread starter Thread starter vjp2.at
  • Start date Start date
V

vjp2.at

How do you say
"If a field named frog does not exist, create it;
If the field dog is like '*tail*' then update frog to be 'no';" in SQL.

Much Obliged.

- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
....

by field do you mean a column names frog or a record which has a
column named animal type and the data is frog

if you want to create a new field then modify the table and add the
field then update it with a sql command.

update mytable set newcolumn = "no"
where fieldnameddog like *tail*

i am not sure if access supports DDL language but regardless it is
eaiser to just manually create it

Regards
Kelvan
 
Much obliged.

WHat I meant was that I wanted to create a new field
if that field does not exist; then I wanted to
fill in values for that field.

My thinking was to create a set of SQL;SQL;SQL; queries that
could be run on several databases.



- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
 
You can use DDL queries and accept that you will get an error if the
field already exists.

This will create a one field table. You can create multiple fields if
you wish

CREATE TABLE XXXXX (TheDate DateTime Constraint PKTheDate Primary Key)

This will add a new field to an existing table and if the field exists
it will generate an error.

ALTER TABLE XXXXX Add Column ADate DateTime
 
basically from my reading you have to do it in vba using ado
programming you can add fields in sql but you cannot check if one
exists

Regards
Kelvan
 
Back
Top