Question : Visual Fox Pro query to SQL Server Query

Is there an easy way to convert a Fox Pro query to a SQL Server query?  

I have a friend that sent me a HUGE Fox Pro query to convert to SQL Server, and I really don't feel like spending a lot of time on it.  

I'm pretty good with SQL Server...  at least I can get it to do what I need it to do.  However, I don't know anything about Fox Pro.

Here's a VB/C# converter that is kind of what I'm thinking of:
    http://www.developerfusion.com/tools/convert/vb-to-csharp/

Thanks!

Answer : Visual Fox Pro query to SQL Server Query

The skelet of the procedure with a few commands could look like this one. You should be able to compare SQL language against xBase code.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
CREATE PROCEDURE dbo.sp_YourProcName 
    -- LPARAMETERS lcFilter, lcDateRange, lcSortRange, lcAdvFilter, lcOtherVariable, lcSortOrder
    @lcFilter varchar(10), 
    @lcDateRange varchar(30), 
    @lcSortRange varchar(30), 
    @lcAdvFilter varchar(30), 
    @lcOtherVariable varchar(30), 
    @lcSortOrder varchar(30)
AS
BEGIN
SET NOCOUNT ON;
 
DECLARE @sqlCmd varchar(4000)
 
IF UPPER(@lcFilter) IN ('( SHIPPED )', '( INVOICED )', '( PAID )', '( SOLD )')
BEGIN
  IF UPPER(@lcFilter) = '( SHIPPED )'
  BEGIN
    SET @sqlCmd = 'SELECT Shitem.finvqty, Shitem.fmeasure, SHITEM.FAC, Shitem.fpartno, shitem.frev as fpartrev, shitem.fcudrev, ' + 
	         'CASE WHEN inmast.fluseudrev IS NOT NULL AND inmast.fluseudrev = 1 THEN shitem.fcudrev ELSE shitem.frev END AS fcdisprev, ' + 
	         'Shitem.fshipno, ' + 
	         'Shitem.fshipqty, Sorels.fsono, Sorels.finumber, Sorels.frelease, ' + 
	         'Sorels.finvamount, Sorels.finvqty, Sorels.fnetprice, Sorels.forderqty, ' + 
	         'Sorels.funetprice, Somast.fsalcompct, Somast.fsoldby, Somast.fterr, ' + 
	         'ShMast.fShipDate ' + 
	         'FROM shitem ' + 
	         'JOIN shmast ' + 
	         'ON ShMast.fShipNo = ShItem.fShipNo ' + 
	         'JOIN sorels ' + 
	         'ON shitem.fsokey = Sorels.fsono + sorels.fInumber + sorels.frelease ' + 
	         'JOIN somast ' + 
	         'ON Sorels.fsono = Somast.fsono ' + 
	         'LEFT OUTER JOIN inmastx inmast ' + 
	         'ON inmast.fpartno = shitem.fpartno ' + 
	         'AND inmast.frev = shitem.frev ' + 
	         'AND inmast.fac = shitem.fac ' + 
	      	 'WHERE fconfirm = ''Y'' ' + 
	         '  AND ' + @lcDateRange +  
	         '  AND ' + @lcSortRange +  
	         '  AND ' + @lcAdvFilter +  
	         ' ORDER BY ' + @lcSortOrder
  END
  ELSE IF UPPER(@lcFilter) = '( INVOICED )'
  BEGIN
    SET @sqlCmd = 
  END
  ELSE IF UPPER(@lcFilter) = '( PAID )'
  BEGIN
    SET @sqlCmd = 
  END
  ELSE IF UPPER(@lcFilter) = '( SOLD )'
  BEGIN
    SET @sqlCmd = 
  END
  
  EXECUTE(@sqlCmd)
  
END
ELSE
BEGIN
  SET @sqlCmd = 'SELECT Glcshi.fdPaidDate as fdArInvPaid, Commpay.*, Slspns.fLastName, ArMast.fcCompany,  ' + 
				'ArMast.fbCompany, ApVend.fCompany, ArMast.fcStatus as InvStat ' + 
				'FROM Commpay ' + 
				'LEFT JOIN ARMAST ' + 
				'ON ARMAST.fcInvoice = CommPay.fcArInv ' + 
				'LEFT JOIN GLCSHI ' + 
				'ON GlCshi.fcInvoice = ArMast.fcInvoice AND GlCshi.fcPayClass = ''R'' ' + 
				'AND GlCshi.fcType = '' '' ' + 
				'LEFT JOIN SLSPNS ' + 
				'ON SLSPNS.fSalesPn = CommPay.fSalesPn ' + 
				'LEFT JOIN APVEND ' + 
				'ON APVEND.fVendNo = CommPay.fcVendor ' + 
				'WHERE ' + @lcFilter +  
				'  AND ' + @lcDateRange +  
				'  AND ' + @lcSortRange +  
				'  AND ' + @lcAdvFilter 
  
  IF @lcSortOrder <> ' ' 
    SET @sqlCmd = @sqlCmd + ' ORDER BY ' + @lcSortOrder
  
  EXECUTE(@sqlCmd)
  
  -- Above SELECT can be stored in a temporary table because results are processed
  -- in another three SELECT commands in FoxPro
  
  -- Here should follow the last three SELECTs converted from xBase language to SQL
  --   or you may incorporate these SELECTs into the previous one
  
END
Random Solutions  
 
programming4us programming4us