Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending a list from vfp
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00827267
Message ID:
00829213
Views:
54
Hi Kelly,

Below you'll find code that works of VFP and SQL Server test data. It shouldn't be hard to adjust to your requirements.
1. Create following stored procedure in the SQL Server Northwind database
IF EXISTS (SELECT name 
	   FROM   sysobjects 
	   WHERE  name = N'usp_OrdersByList' 
	   AND 	  type = 'P')
    DROP PROCEDURE usp_OrdersByList
GO
CREATE PROCEDURE usp_OrdersByList 
	@XmlList varchar(4000) = 0
AS
DECLARE @hDoc int
EXECUTE sp_xml_preparedocument @hDoc OUTPUT, @XmlList
SELECT * FROM orders ord
	JOIN OPENXML(@hDoc, 'VFPData/crslist') WITH (customer_id char(6) ) lst 
		ON ord.CustomerId = lst.customer_id
EXECUTE sp_xml_removedocument @hDoc
Now, run following code from VFP. Don't forget to put your server name and login info.
OPEN DATABASE (HOME(2) + "\tastrade\data\tastrade")
lcXml = ""
SELECT TOP 10 customer_id ;
	ORDER BY 1 ;
	FROM customer ;
	INTO CURSOR crsList
? CURSORTOXML("crsList", "lcXml", 2)
lcDB = "NorthWind"
lcServer = "..."
lcConnStr = "DRIVER=SQL Server;" + ;
	"UID=Administrator;" + ;
	"Trusted_Connection=Yes;" + ;
	"SERVER=" + lcServer + ";" + ;
	"DATABASE=" + lcDB
lnConn = SqlStringConnect(lcConnStr)
IF lnConn < 0
	*? _processodbcerror()
	RETURN
ENDIF
lnResult = SQLEXEC(lnConn, "EXEC usp_OrdersByList ?lcXml", "cesOrderList")
IF lnResult < 0
	*? _processodbcerror()
	RETURN
ENDIF
Sqldisconnect(0) 
BROWSE NOWAIT
>Sorry it took so long to reply but I have done some testing and have came to a few conclusions. One is that I have found really no speed difference between sending and entire sql string (one number at a time) and then appending the result into a cursor in VFP as apposed to sending a function call or proc call (one number at a time) and appending that result into a vfp cursor. Second, in order to send a really long list I need to use XML (I think). However, I am not sure how to handle the XML. I created a cursor of member numbers and ran the cursortoxml() and it created an xml file. What it does not look like is the example that you pointed me to. So, that raised more questions.
>
> 1. Do I send the filename and path to the sp_xml_preparedocument or something like a memory variable?
>
> 2. Why does the cursortoxml() not create a format (that appears) not to be able to be used with that stored procedure? Or if it does where am I going wrong?
>
>Sorry for the rambling on but I have been gone a while.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform