Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Update SQL table from FoxPro OpenQuery SubSelect

Posted on 2009-04-06
5
837 Views
Last Modified: 2012-05-06
Greetings Experts,  

I have a project where I have SQL server tables and Visual Fox Pro tables.  I need to update an inventory qty in the SQL table, based on the qty located in a Visual Fox Pro table.   I created a linked server, but need help with syntax.  I am stuck on matching the SKU in the SQL table to the where condition in the openquery subselect.   Here is what I have, that is not working:

UPDATE [MMan].[dbo].[items]

   SET qty = (select * from openquery(VFPRO, 'Select saq_qty from scsaqty where saq_sku = [MMan].[dbo].[items].itemno'))
     
GO


I get the following error:  

Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "Select saq_qty from scsaqty where saq_sku = [MMan].[dbo].[items].itemno" for execution against OLE DB provider "VFPOLEDB" for linked server "VFPRO".


Your help would be greatly appreciated.

Best Regards,

Keith
0
Comment
Question by:kdwood
  • 2
  • 2
5 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24078892
Try this query:

UPDATE [MMan].[dbo].[items]
SET qty = t2.saq_qty
FROM [MMan].[dbo].[items] t1, (select * from openquery(VFPRO, 'Select saq_sku, saq_qty from scsaqty')) t2
where t1.itemno = t2.saq_sku


     
0
 
LVL 42

Expert Comment

by:pcelba
ID: 24078993
The command  'Select saq_qty from scsaqty where saq_sku = [MMan].[dbo].[items].itemno' is executed outside of SQL Server so it knows nothing about "[MMan].[dbo].[items].itemno".

I don't know exact syntax of linked server tables usage but I would guess you may use following (suppose saq_sku is of the same data type as items.itemno):

UPDATE [MMan].[dbo].[items]
   SET qty = fox.saq_qty
FROM [MMan].[dbo].[items] i
INNER JOIN (select * from openquery(VFPRO, 'Select saq_qty, saq_sku from scsaqty')) fox ON fox.saq_sku = i.itemno

Another possibility is to update [MMan].[dbo].[items] directly from FoxPro by e.g. SQLEXEC() function call.

0
 
LVL 10

Author Comment

by:kdwood
ID: 24079016
Thanks for the reply rrjegan,

I tried your query and at first I didn't think it would work because the query window in SQL Server Management Studio, was putting red underlines under the following:

t2.saq_QTY  and t2.saq_sku.   It was indicating that they were invalid column names.

However, I executed the query and it ran successfully and updated 214 rows.

Are the red underlines just a quirk because we are using the openquery method?

0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24079040
Yes. The server doesn't know those are column names available in in your Foxpro table. But when it executes it through OPENQUERY it finds that it is a proper table and column and hence it executes it fine.

Hope that resolved your issue.
0
 
LVL 10

Author Closing Comment

by:kdwood
ID: 31567104
Thank you for the quick response.  The solution works great.   Best regards.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question