Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Executing two command in one string
Message
 
 
À
22/03/2013 08:18:12
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01568990
Message ID:
01569021
Vues:
33
>>>>Hi,
>>>>
>>>>I think I can sent two command to SQL Server from VFP app (using SQLEXEC()) but I am not sure what separator to use. Should it be semi colon? For example if I want to alter a column and then set a value into this column, can I do the following:
>>>>
>>>>
>>>>cSqlCmd = "alter table MyTable alter column MyFld1 char(30); update MyTable set MyFld1 = repl('0',30) where len(MyFld1) = 0"
>>>>nRetunr = SQLEXEC(nConn, cSqlCmd)
>>>>
>>>>
>>>>Will the above work? TIA
>>>>
>>>>UPDATE. I ran it and it works.
>>>
>>>Yes, you can and should use semicolon. You can also use text endtext to put commands in multiple lines to improve readability.
>>
>>What would be an exmaple of my string above using 'text / endtext'?
>
text to cSqlCmd textmerge
>alter table MyTable alter column MyFld1 char(30); 
>
>update MyTable set MyFld1 = repl('0',30)
>   where len(MyFld1) = 0
>endtext
>nRetunr = SQLEXEC(nConn, cSqlCmd)
>
>It runs the same, but it's much easier to maintain. Consider the case when your nReturnr goes over 20 (it's the number of returned cursors). You can send kilobytes of text in a SQL command, and retrieve many cursors all in one go. These kilobytes of TSQL script would be very hard to maintain if they were built with string concatenation. Text/endtext enables you to have a script laid out as text - with all the benefits of textmerge. My life would be much more complicated without it.

Thank you. So when you are saying 'kilobytes of text' you mean there is no limit on the length of the SQL command that you send to SQL Server?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform