Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting Record into SQL from VFP App
Message
From
16/08/2000 19:40:24
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00405841
Message ID:
00405891
Views:
30
>I've almost got it, but not quite. I've been able to insert a record if I use actual values, but not if I use variables. Here is the command I'm using that works and then what I want to do:
>
>sqlexec(gnConnHandle,"Insert into CQIPATIENTS (FacilityID, DeptID, PatNumber,LastName,FirstName) Values (1,1,'C11','Kelly','Kirk')")
>
>The above statement works, but I want to do the following:
>
>sqlexec(gnConnHandle,"Insert into CQIPATIENTS (FacilityID, DeptID, PatNumber,LastName,FirstName) Values (gnFacID,gnDeptID,gcPatNumber,lcLastName,lcFirst)")
>
>This one comes back and tells me:
>gnFacID is not permitted in this context. Only constants, expressions, or variables are allowed here. Column names are not permitted.
>
>I have also tried putting the @ in front of each variable, but to no availe

Kirk, you are close!

sqlexec(gnConnHandle,"Insert into CQIPATIENTS (DeptID, PatNumber,LastName,FirstName) Values (?gnDeptID,?gcPatNumber,?lcLastName,?lcFirst)")

Using the question mark in the SQLExec() command, VFP knows what you want. Your attempt didn't work because VFP sent all the string to SQLServer, which, of course, has no idea what gnFacID is!

Note: as I think you stated, FacilityID is an identity column, so you cannot put a value into it. SQLServer will take care of it. That is why I removed it from the SQLExec() command.

Hope this helps!
Sylvain Demers
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform