Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Substitution with SQLEXEC 1

Status
Not open for further replies.

ariftvt

Programmer
Aug 25, 2008
18
AE
what is the best practice to do a Macro Substitution with SQLEXEC.
for example:-
bbb=100

sqlexec(handle,"insert into table1(fld1,fld2) values(value1,value2)"

in this case how can i substitute value1 with the variable 'bbb'

pls help
 
Use parameters:

Code:
bbb=100
sqlexec(handle,"insert into table1(fld1,fld2) values(?m.bbb, value2)")



Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Another method is to build the entire command, inclusive of the variables, and then put it into the SQLEXEC() line.

Code:
bbb=100
value2 = "ABC"
mcCommand = "insert into table1(fld1,fld2) values(" + ALLTRIM(STR(bbb)) + ", '" + Value2 + "')"

SQLEXEC(mnConnectionHandle, + mcCommand)

Good Luck,
JRB-Bldr
 
Ariftvt,

You've received two excellent suggestions. Of the two, I'd favour Borislav's solution, mainly because it will take care of serveral server-specific issues automatically.

For example, if your back-end is SQL Server, the query could fail if you send a string containing an apostrophe. By using the "?" syntax, issues like that are taken care of.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Great!!...thanks Borislav and all others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top