Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting into SQL table from Cursor using SQLEXEC()
Message
 
 
To
26/10/2005 11:08:38
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows 2000 SP4
Database:
MS SQL Server
Miscellaneous
Thread ID:
01062223
Message ID:
01062416
Views:
10
>Hello,
>I have a cursor and I want to append it to a SQL Server table. I have to use SQLEXEC though. I know how to do it when you add the table to the designer, but now I am stumped and and can't seem to find the right documentation. TIA!
>
>MAC

If you use the field names in the cursor, you do not have to worry about data types as ling as the fields in the SQL Server table are compatible:
local lnKount, lcSQL, lcList, lcValues, lnI, laFields[1]
lnKount = afields(laFields, 'crsMyCursor')
lcSQL = []
lcList = [(]
lcValues = [(]
for lnI = 1 to lnKount
    lcList = lcList + laFields[lnI, 1]
    lcValues = lcValues + [?crsMyCursor.] + laFields[lnI, 1]
    if lnI < lnKount
        lcList = lcList + [, ]
        lcValues = lcValues + [, ]
    endif
endfor
lcList = lcList + [)]
lcValues = lcValues + [)]
lcSQL = [insert into MySQLTable ] + lcList + [ VALUES ] + lcValues
*!* all code above here can be rolled into a class method where you can pass
*!* either the cursor name of an array of fields to generate the code for you.
*!* you can do the same for update sql as well. (i.e., make it generic and reusable)
*!* the sql code only needs to be generated ONCE.
select crsMyCursor
scan
    lnReturn = sqlexec(nHandle, lcSQL)
    if lnReturn < 0
       *!* handle failure here
    endif
endscan
Mark McCasland
Midlothian, TX USA
Previous
Reply
Map
View

Click here to load this message in the networking platform