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
|