Alter table and update with ADO
- From: "Richard" <abbeyroad@xxxxxxxxxxxxxx>
- Date: Thu, 25 Aug 2005 10:30:48 -0400
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;
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!
.
- Follow-Ups:
- Re: Alter table and update with ADO
- From: Guillem
- Re: Alter table and update with ADO
- From: Jon Jacobs
- Re: Alter table and update with ADO
- Prev by Date: Re: Populate dataset with text file
- Next by Date: Re: How do I capture Delphi 5 TADODataset timeout error consistently?
- Previous by thread: Re: SQL error
- Next by thread: Re: Alter table and update with ADO
- Index(es):
Relevant Pages
|