Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditionally updating fields
Message
From
11/10/2016 14:14:46
 
 
To
11/10/2016 10:32:53
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:
01641835
Views:
59
>Hi,
>
>I am working on changing an import program where the user provides an Excel file with some key columns filled in to identify the rows to be updated and then values can be filled in in some columns and left blank in other columns. If the column is blank I don't want to change the existing data. If there is a value in the column then I will change the existing data. Currently I update all fields with whatever values ar ein the spreadsheet so if the column is blank, that field will end up being changed to a blank value.
>
>I import to a cursor, then scatter the imported values and run an SQL statement like this:
>
>
		UPDATE Employees 
>		SET emp_firstname = ?m.emp_firstname
>			,emp_middlename = ?m.emp_middlename
>			,emp_lastname = ?m.emp_lastname
>			,emp_dob = ?m.emp_dob
>			,emp_clifk = ?m.emp_clifk
>			,emp_number = ?m.emp_number
>			,emp_relfk = ?m.emp_relfk
>			,emp_empfk = ?m.emp_empfk
>			,emp_sexfk = ?m.emp_sexfk
>			,emp_active = 1
>			,emp_transfer = ?m.emp_transfer
>			,emp_email = ?m.emp_email
>			,emp_title = ?m.emp_title
>			,emp_pensionpolicy = ?m.emp_pensionpolicy
>			,emp_BIR = ?m.emp_BIR
>			,emp_NIS = ?m.emp_NIS
>			,emp_height = ?m.emp_height
>			,emp_weight = ?m.emp_weight
>			,emp_phone = ?m.emp_phone
>			,emp_employdate = ?m.emp_employdate
>			,emp_occupation = ?m.emp_occupation
>			,emp_maritalstatus = ?m.emp_maritalstatus
>			,emp_address1 = ?m.emp_address1
>			,emp_address2 = ?m.emp_address2
>			,emp_address3 = ?m.emp_address3 
>		WHERE emp_pk = ?m.emp_pk
>
>
>Is there an easy way to change this to only update fields where the variables are not blank (or I could set them to null if that helps)?
>
>I don't want to have to change it to a bunch of statements like this if there is an easier way:
>
>
>IF NOT ISNULL(m.emp_firstname) AND NOT ISEMPTY(m.emp_firstname) 
>		UPDATE Employees 
>		SET emp_firstname = ?m.emp_firstname
>		WHERE emp_pk = ?m.emp_pk
>ENDIF
>
>IF NOT ISNULL(m.emp_middlename) AND NOT ISEMPTY(m.emp_middlename) 
>		UPDATE Employees 
>		SET emp_middlename = ?m.emp_middlename
>		WHERE emp_pk = ?m.emp_pk
>ENDIF
>
I think I should be able to use IIF() to update only when the parameter passed in is not null.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform