Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Conditionally updating fields
Message
De
13/10/2016 10:25:14
 
 
À
13/10/2016 06:46:19
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 SP2
Database:
MS SQL Server
Divers
Thread ID:
01641827
Message ID:
01641875
Vues:
52
>
>maybe less duplicated code and easier to maintain:
>
>
>local cSQL, cField, aa, iField
>
>text to cField noshow flags 1 && additional fields go into this list
>emp_middlename
>emp_lastname
>emp_dob
>emp_clifk
>emp_number
>emp_relfk
>emp_empfk
>emp_sexfk
>emp_transfer
>emp_email
>emp_title
>emp_pensionpolicy
>emp_BIR
>emp_NIS
>emp_height
>emp_weight
>emp_phone
>emp_employdate
>emp_occupation
>emp_maritalstatus
>emp_address1
>emp_address2
>emp_address3
>endtext
>
>cSQL = ''
>for iField = 1 to ALines(aa, m.cField, 5)
>	cField = m.aa[m.iField]
>	cSQL = m.cSQL + Iif(IsNull(Evaluate('m.' + m.cField)), '', ',' + m.cField + '=?m.' + m.cField)
>endfor
>
>result = Iif(empty(m.cSQL);
>	, .null.;
>	, executeQuery('UPDATE Employees SET ' + Ltrim(m.cSQL, ',') + ' WHERE emp_pk = ?m.emp_pk');
>	)
>
Nicely done!
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform