Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: sri kishan
  Where is sri kishan?
 
 India
 sri kishan
 To: Samir H.
  Where is Samir H.?
 Yogyakarta
 Indonesia
 Samir H.
 Tags
Subject: RE: how we can update record with one sql
Thread ID: 310834 Message ID: 310861 # Views: 30 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Sunday, June 26, 2011 8:11:20 AM         
   


i have seen single sql in foxite but i did not remember the name of the thread.

i think that was posted by Rahul

 *** method 1

select table1.pk from table1 where table1.pk=table2.pk into curs tempcursor
do case
case _tally>0
update ...
otherwise
insert ...
endcase


*** method 2

update table1 set table1.filed1=table2.field1 where table1.pk=table2.pk
if _tally=0
   insert into table1 (field1) select (field1) from table2 where ...
endif
 


which is best from the above 2

Regards




> > we are using this kind of sql for update records
> >
> >
> > update table1 set table1.filed1=table2.field1 where table1.pk=table2.pk
> > 
> > if _tally=0
> >   insert into table1 (field1) select (field1) from table2 where ...
> > endif
> > 
> > 

> >
> > how we can do this with one sql.
> >
> > Regards
>
> I guess you cannot because UPDATE and INSERT do two different things. What you could do is a SELECT to check if there is such a record, then a IF-ELSE-ENDIF, with either a Update or a Insert.
>
> Regards
> Samir

ENTIRE THREAD

how we can update record with one sql Posted by sri kishan @ 6/25/2011 7:47:45 PM
RE: how we can update record with one sql Posted by Stefan Wuebbe @ 6/25/2011 8:27:20 PM
RE: how we can update record with one sql Posted by sri kishan @ 6/25/2011 8:50:01 PM
RE: how we can update record with one sql Posted by Samir H. @ 6/25/2011 8:33:37 PM
RE: how we can update record with one sql Posted by sri kishan @ 6/26/2011 8:11:20 AM
RE: how we can update record with one sql Posted by Samir H. @ 6/26/2011 10:49:14 AM
RE: how we can update record with one sql Posted by Anders Altberg @ 6/25/2011 11:27:29 PM