Re: Alter table and update with ADO



Hi,

Richard wrote:

> Hello,
>
> I am using an ADO SQLQuery to check to see if structure updates are
> needed for a database and apply them if they are needed. In one case
> I am checking to see if a field exists in a table, and if not I add
> the field and then I need to update the new field to contain data
> from another table (this isn't going to be a foreign key by the way).
> But the query errors out saying the field doesn't exist. Here's the
> statement:
>
> if not exists (SELECT *
> FROM SYSCOLUMNS
> WHERE ID = OBJECT_ID('TABLENAME')
> AND Name = 'NEWCOL'
> )
> begin
> alter table [TABLENAME]
> add NEWCOL integer;
>
> Update tablename set newcol=(select X from Othertable where
> y=tablename.y); end;


are you sure this statement should work? It looks like PL/SQL to me,
and AFAIK not all RDBMS support that. Have you tried to do it from your
database console?

>
> The query fails with 'Field newcol not found'. If I run this in
> Query Analyzer I could use the 'Go' statements to make sure each
> statement is executed when it needs to be so this doesn't happen, but
> I don't know of an equivelent using ADO. Is there an equivalent or
> is there another way to write this sql statement so this will work?
> Thanks!


an ADOQuery will try to return a result. It's specifically designed for
that purposes, not for altering databases. I would suggest to try with
either an ADODataset or an ADOCommand

--
Best regards :)

Guillem Vicens
Dep. Informática Green Service S.A.
www.clubgreenoasis.com
--
in order to contact me remove the -nospam
.



Relevant Pages

  • Alter table and update with ADO
    ... I am using an ADO SQLQuery to check to see if structure updates are needed ... AND Name = 'NEWCOL' ... The query fails with 'Field newcol not found'. ...
    (borland.public.delphi.database.ado)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: OT: SQL
    ... query processing. ... FROM Employees e, Employees m, Management mgt ... Manager and Employee Salaries. ... The scheme used does not model database files in general, ...
    (sci.logic)
  • Re: access 2003
    ... I removed the parameters from the form query source. ... boxes from the form header, events, code, etc and ran the form query source ... forms queries and the SQL because syntax of the SQL will change randomly. ... the Access 97 database, I wouldn't have thought any expressions would be ...
    (microsoft.public.access.conversion)
  • RE: Import external data - web query
    ... Your reply for my query is very extensive, this is for importing a file from ... The data source I want isn't listed in the Select Data Source dialog box. ... information used to connect to a database. ... Check your driver First, make sure you have the right ODBC driver (Open ...
    (microsoft.public.excel.misc)