Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating SQL Server table
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01655887
Message ID:
01655901
Vues:
54
I was about to post same thing as Borislav, was a minute to late... Anyways, SQL generates two "cursors" you can use in the OUTPUT, inserted and deleted, the first one represents the new (inserted) values and the second one represent the old (deleted) values, it is easy to see in this sample code:
declare @test table (pk int, event varchar(10), EventTime datetime)

insert into @test (pk, event, EventTime) values (1, 'Start', '')

update @test  set eventtime = getdate() output deleted.pk, deleted.eventtime, inserted.eventtime where pk = 1
>>>>>Hi,
>>>>>
>>>>>I am calling SQL Update command from VFP application. Since I don't know if the matching record is found in the SQL Server, I want to have the results; so that I can count how many record were updated. I thought I can add the name of a cursor and "capture" this. But it does not seem to work. Here is what I am doing:
>>>>>
>>>>>
>>>>>cSqlUpdate = "update mytable set field1 = '1233' where id_field = 'ABC'"
>>>>>nResult = SQLEXEC(hCon, cSqlUpdate, "cur_result")
>>>>>
>>>>>
>>>>>I thought that the cursor "cur_result" would be created on successful update. But Select ("cur_result") is 0 after an update that I see worked. What am I missing?
>>>>>
>>>>>TIA
>>>>>
>>>>
>>>>UPDATE statement do not create cursor.
>>>
>>>Thank you.
>>
>>
>>If you want updated records as cursor than you ca use OUTPUT statement:
>>
>>cSqlUpdate = "update mytable set field1 = '1233' where id_field = 'ABC' OUTPUT INSERTED.*"
>>nResult = SQLEXEC(hCon, cSqlUpdate, "cur_result")
>>SELECT cur_result
>>BROW NORMAL
>>
>
>Thank you. What is the purpose of the word "INSERTED.*" in your code above? I am updating (not inserting).
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform