SelectCmd = ; "select CD_ID, CD_VAL, [order], " + ; "CD_DESC, MOD_DTTM, MOD_BY_ID, CONV_BAT_ID " + ; "from MyTable"3) Once you have the data in a VFP cursor with a field named "order" in the cursor, VFP can handle it OK, including constructing the update statement and handling the ?table.order substitution, but cannot automatically change the update command to put brackets around the order field before sending to SQL Server without a little fancy footwork in defining properties or trapping events.
UpdateNameList = ; "code_id MyTable.CD_ID, code MyTable.CD_VAL, " + ; "code_desc MyTable.CD_DESC, mod_dttm MyTable.MOD_DTTM, " + ; "mod_by_id MyTable.MOD_BY_ID, " + ; "conv_bat_id MyTable.CONV_BAT_ID, order [MyTable.order]"However, using this syntax in UpdateNameList DOES work:
order MyTable.[order]With the fieldname in brackets AFTER the "table.", CA cross-references the VFP order field with MyTable.[order] and strips off the MyTable." part of it, leaving [order], which it then puts into the Update statement. Here is the resulting VFP SQL statement, trapped in the BeforeUpdate method in the cUpdateInsertCmd parameter:
UPDATE MyTable SET [order]=?codes.order, MOD_DTTM=?codes.mod_dttm,MOD_BY_ID=?codes.mod_by_id WHERE CD_ID=?OLDVAL('code_id','codes') AND CD_VAL=?OLDVAL('code','codes') AND MOD_DTTM=?OLDVAL('mod_dttm','codes')BTW, to see what is about to be sent to SQL Server, you can do this in the BeforeUpdate method of CA:
FUNCTION BeforeUpdate(cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd) DODEFAULT(cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd) _cliptext = cUpdateInsertCmd ENDFUNCThen you can paste from the clipboard to see what the cUpdateInsertCmd looked like.Alternatively to setting up the brackets in the UpdateNameList, you can put code in the BeforeUpdate method to STRTRAN the field:
FUNCTION BeforeUpdate(cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd) DODEFAULT(cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd) cUpdateInsertCmd = STRTRAN(cUpdateInsertCmd, "order=?", "[order]=?") _cliptext = cUpdateInsertCmd ENDFUNCEither of these approaches will result in success, but I like the UpdateNameList much better because it will be used both for Update and Insert commands. Otherwise, you would have to trap both the BeforeUpdate and BeforeInsert events.
exec sp_executesql N'UPDATE MyTable SET order=@P1 , MOD_DTTM=@P2 ,MOD_BY_ID=@P3 WHERE CD_ID=@P4 AND CD_VAL=@P5 AND MOD_DTTM=@P6 ', N'@P1 float,@P2 varchar(23), @P3 varchar(8),@P4 varchar(10),@P5 varchar(3),@P6 varchar(23)', 2.000000000000000e+000, '2006-07-21 15:49:07.380', 'david ', 'ADV_INSTR ', 'A ', '2006-07-21 15:40:02.387'and this for the corrected version:
exec sp_executesql N'UPDATE MyTable SET [order]=@P1 , MOD_DTTM=@P2 ,MOD_BY_ID=@P3 WHERE CD_ID=@P4 AND CD_VAL=@P5 AND MOD_DTTM=@P6 ', N'@P1 float,@P2 varchar(23), @P3 varchar(8),@P4 varchar(10),@P5 varchar(3),@P6 varchar(23)', 2.000000000000000e+000, '2006-07-21 15:49:07.380', 'david ', 'ADV_INSTR ', 'A ', '2006-07-21 15:40:02.387'The only difference is that the field "order" is now surrounded by brackets. However, both of them show that VFP correctly interpreted the ?codes.order before turning it into a parameter to send to SQL Server. So, the problem is with SSvr needing the order= to be [order]=.