Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I use field(x) in SQL Update command?
Message
De
08/10/2007 13:47:10
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01259499
Message ID:
01259508
Vues:
19
>>
>>
>>lcField = field(nColumn)
>>update mytable set &lcField = 222 where MyField = "SomeValue"
>>
>
>A follow up question, if I may. If/when I move my DB to SQL Server, will there be a way to maintain the same table structure (relying on column no)?

No, If you use SPT.
SQL Server has no such function as FIEDLS() and no macros.
Of course you could build a dynamic SQL based on INFORMATION_SCHEMA.COLUMNS:
DECLARE @lcSQL varchar(200)
SELECT @lcSQL = 'update mytable set ' + COLUMN_NAME + ' = 222 where MyField = ''SomeValue'''
       FROM INFORMATION_SCHEMA.COLUMNS
WHERE Table_Name = 'mytable' AND Ordinal_Position = @nColumn -- Where nColumn is a column number
EXEC (@lcSQL)
not tested at all :-)

So in VFP you could use something like this:
mColumn = 1

TEXT TO lcSQL NOSHOW TEXTMERGE
     DECLARE @lcSQL varchar(200)
     SELECT @lcSQL = 'update mytable set ' + COLUMN_NAME + ' = 222 where MyField = ''SomeValue'''
            FROM INFORMATION_SCHEMA.COLUMNS
     WHERE Table_Name = 'mytable' AND Ordinal_Position = <<nColumn>>
     EXEC (@lcSQL)
ENDTEXT

IF SQLEXEC(...., lcSQL) < 0
   AERROR(laError)
   MessageBox(laError[1,2])
ENDIF
But if you use CA or Remote view to handle data, there is no need of any of these. You could update VFP cursor and than just use TABLEUPDATE().
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform