>>>* f1: char, f2: datetime, f3:datetime >>>cInsertCmd = "insert into myTable (f1, f2, f3) values (?m.Value1, ?m.Value2, ?m.Value3)" >>>SQLPrepare(m.lnHandle,m.cInsertCmd) >>>m.ldStart=date() >>>for ix=1 to 5 >>> m.Value1 = cdow(m.ldStart+m.ix-1) >>> m.VAlue2 = m.ldStart + m.ix - 1 >>> m.Value3 = datetime() - (m.ix * 3600) >>> SQLExec(m.lnHandle) >>>endforCetin
>for ix=1 to 5 > m.Value1 = cdow(m.ldStart+m.ix-1) > m.VAlue2 = m.ldStart + m.ix - 1 > m.Value3 = datetime() - (m.ix * 3600) > insert into myTable (f1, f2, f3) values (m.Value1, m.Value2, m.Value3) >endfor >When it's an SQLExec() command you can't simply do this and need a string for 2nd parameter, right? And with SQLserver each time you pass an SQLExec(m.lnHandle, m.lcSQLCommand), m.lcSQLCommand must be compiled before execution. IOW "insert ..." command is first compiled and then executed on SQL server side. If you need multiple inserts with same cInsertCmd skeleton (where only parameter values change) to speed things up you first SQLPrepare(). It does the compilation part. Then you simply call SQLExec(m.lnHandle) within the loop. It is same as:
>use employee >cInsertCmd = "insert into mySQLServerTable (employeeID, notes)"+; > " values "+; > "(?employee.emp_id,?employee.Notes)" >SQLPrepare(m.lnHandle,m.cInsertCmd) >scan > SQLExec(m.lnHandle) >endscan >SQLExec(m.lnHandle,"select * from mySQLserverTable",'myCursor') >select myCursor >browsePrepare the string with SQLPrepare() and execute per VFP side record within scan..endscan. Though this is not the recommended way to do it for bulk operations, this is a sample why you shouldn't try to convert values in string. Or yet another sample. Suppose you want to store the contents of a file as is on SQL server along with datetime you made the insert:
>m.lcContents = FileToStr("c:\some path\somefilename.ext") >m.When = datetime() >SQLExec(m.lnHandle, ; > "insert into myTable (InsertedAt,FileContent) values (?m.When,?m.lcContents)") >Cetin,