Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditionally updating fields
Message
From
13/10/2016 10:25:14
 
 
To
13/10/2016 06:46:19
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
MS SQL Server
Miscellaneous
Thread ID:
01641827
Message ID:
01641875
Views:
51
>
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform