Still on Pervasive SQL 2000i.
PCC query speed is roughly 5 seconds. VBScript query time is close5 to 5 minutes.
This is the query in VBScript:
' Connect to the Max Database
set conn = CreateObject("ADODB.Connection")
conn.Open "DSN=MaxDB"
' Get the total sales for the time period for the current product
sql = "SELECT ""Invoice Detail"".""PRTNUM_32"", ""Part Master"".""PMDES1_01"", ""Part Master"".TYPE_01, "
sql = sql & "SUM(IF(""Invoice Detail"".STYPE_32 = 'CU', 1, -1) * ""Invoice Detail"".INVQTY_32) AS totalQty, "
sql = sql & "SUM(IF(""Invoice Detail"".STYPE_32 = 'CU', 1, -1) * ""Invoice Detail"".INVQTY_32 * ""Invoice Detail"".""PRICE_32"") AS totalValue, "
sql = sql & """Lot Tracking Hist"".""LOTNUM_72"" "
sql = sql & "FROM ""Invoice Master"", ""Invoice Detail"", ""Part Master"", ""Lot Tracking Hist"" "
sql = sql & "WHERE ""Part Master"".COMCDE_01 = '" & trim(rs("COMCDE_01")) & "' AND ""Invoice Detail"".INVDTE_32 "
sql = sql & "BETWEEN '" & dateStart("Max") & "' AND '" & dateEnd("Max") & "' "
sql = sql & "AND (""Lot Tracking Hist"".""TNXCDE_72""='S') AND (""Invoice Master"".""INVCE_31"" = ""Invoice Detail"".""INVCE_32"") "
sql = sql & "AND (""Invoice Detail"".""PRTNUM_32"" = ""Part Master"".""PRTNUM_01"") AND "
sql = sql & "(""Invoice Detail"".""PRTNUM_32"" = ""Lot Tracking Hist"".""PRTNUM_72"") AND "
sql = sql & "(CONCAT(""Invoice Detail"".""ORDNUM_32"", CONCAT(""Invoice Detail"".""LINNUM_32"", ""Invoice Detail"".""DELNUM_32"")) = ""Lot Tracking Hist"".""ORDNUM_72"") "
sql = sql & "AND (""Invoice Detail"".""INVCE_32"" = ""Lot Tracking Hist"".""INVCE_72"") "
sql = sql & "GROUP BY ""Invoice Detail"".PRTNUM_32, ""Part Master"".PMDES1_01, ""Part Master"".TYPE_01, "
sql = sql & """Lot Tracking Hist"".LOTNUM_72 "
sql = sql & "ORDER BY ""Invoice Detail"".PRTNUM_32, ""Lot Tracking Hist"".LOTNUM_72"
set rs1 = conn.Execute(sql, , 1)
I know there is a scalar function (CONCAT) used in the join operation but the exact same query is much faster in PCC.
Any suggestions?
Mighty