Hi all,
My select query is too slow i need a way to speed up the process. Please bare with me while reading through.
The query uses table:
dbo_uk_homes
with fields:
POSTCODE(text)
PRMF(memo)
STRD(text)
STR(text)
LOCDD(text)
LOCD(text)
PTN(text)
CNT(text)
WCD(text)
Now the query has a criteria for POSTCODE field this is a textbox called: EnterPostcode on form called: MA_SEARCH. The user enters a postcode and the query is run.
The query manipulates the field involved like so:
PRMF holds the first line of an address, but for each postcode Field all addresses are listed in one memo field they are divided by semicoloms ";".
The query i have splits each address by the semicolons making them into seperate records with the same postcode. The code then adds fields STRD and STR to the seperate records of the PRMF they are divided by commas, except if the value of PRMF is less than 4 then comma is missed out in that record the part connecting PRMF with STRD OR STR, also if any of the fields are null then it adds on the next field e.g. PRMF, STRD, STR or PRMF, STR OR PRMF, STRD The alias of Expr1 is given to this.
The code also combines fields LOCDD and LOCD together seperated by comma if both are present. This is given alias Expr2
The code also combines fields PTN and CNT together seperated by comma if both are present. This is given alias Expr3
All fields query creates:
POSTCODE
PRMF, STRD, STR AS Expr1
LOCDD, LOCD AS Expr2
CNT, PTN AS Expr3
WCD
This is what slows down process A table name Index is used to store the length of every character in the query. The table index has one field called: num Which at present holds 900 records, which are all numbered from 1 through to 900 each record representing a character in the query result.
This is the query:
txN_searcht1 above is another textbox for optional search entry. It calls a module where: getA1A2A3 is called
This is the module:
Here is an e.g of code in action:
POSTCODE(TEXT)
OP11 9UV
PRMF(memo)
Mossbank Primary School;Northlea Auto Point;Post Office;The Old School Centre;1;2;3
STRD(text)
(NULL)
STR(text)
Jenson Park
LOCDD(text)
Pentwith
LOCD(text)
Mile Haven
PTN(text)
Chester
CNT(text)
(NULL)
WCD(text)
866YT
This will result:
Postcode... Expr1................................................ Expr2... and so on
OP11 9UV Mossbank Primary School, Jenson Park Pentwith, Mile Haven
OP11 9UV Northlea Auto Point, Jenson Park Pentwith, Mile Haven
the rest will be similar the numbers at the end will be like so:
OP11 9UV 1 Jenson Park Pentwith, Mile Haven
OP11 9UV 2 Jenson Park Pentwith, Mile Haven
OP11 9UV 3 Jenson Park Pentwith, Mile Haven
i.e. no comma.
The main thing that is slowing it down is table: index the greater the amount of records it holds the slower the query runs any way to speed up process?
Any help very much appreciated, thank in advance,
M-.
My select query is too slow i need a way to speed up the process. Please bare with me while reading through.
The query uses table:
dbo_uk_homes
with fields:
POSTCODE(text)
PRMF(memo)
STRD(text)
STR(text)
LOCDD(text)
LOCD(text)
PTN(text)
CNT(text)
WCD(text)
Now the query has a criteria for POSTCODE field this is a textbox called: EnterPostcode on form called: MA_SEARCH. The user enters a postcode and the query is run.
The query manipulates the field involved like so:
PRMF holds the first line of an address, but for each postcode Field all addresses are listed in one memo field they are divided by semicoloms ";".
The query i have splits each address by the semicolons making them into seperate records with the same postcode. The code then adds fields STRD and STR to the seperate records of the PRMF they are divided by commas, except if the value of PRMF is less than 4 then comma is missed out in that record the part connecting PRMF with STRD OR STR, also if any of the fields are null then it adds on the next field e.g. PRMF, STRD, STR or PRMF, STR OR PRMF, STRD The alias of Expr1 is given to this.
The code also combines fields LOCDD and LOCD together seperated by comma if both are present. This is given alias Expr2
The code also combines fields PTN and CNT together seperated by comma if both are present. This is given alias Expr3
All fields query creates:
POSTCODE
PRMF, STRD, STR AS Expr1
LOCDD, LOCD AS Expr2
CNT, PTN AS Expr3
WCD
This is what slows down process A table name Index is used to store the length of every character in the query. The table index has one field called: num Which at present holds 900 records, which are all numbered from 1 through to 900 each record representing a character in the query result.
This is the query:
Code:
SELECT I1.POSTCODE, getA1A2A3(Mid$(';' & I1.PRMF & ';',S1.num+1,S2.num-S1.num-1),[Strd],[STR]) AS Expr1, IIf(IsNull([I1].[Locd]),[I1].[Locdd],[I1].[Locd] & IIf(IsNull([Locdd]),"",", " & [Locdd])) AS Expr2, IIf(IsNull([I1].[PTN]),[I1].[CNT],[I1].[PTN] & IIf(IsNull([CNT]),"",", " & [CNT])) AS Expr3, [I1].[WCD]
FROM dbo_UK_homes AS I1, integers AS S1, integers AS S2
WHERE (((I1.POSTCODE)=[Forms]![ma_search2]![EnterPostcode]) AND ((IIf(IIf(Len(Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1))>0,Len(Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1)),0)<4,Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1) & " " & [I1].[Strd] & [I1].[STR],Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1) & IIf(IsNull([Strd]),"",", " & [Strd]) & IIf(IsNull([Strd]) Or Not IsNull([Locdd] & [Locd]),IIf(IsNull([STR]),'',', ' & [I1].[STR])))) Like "*" & IIf([Forms]![Ma_search2]![txN_searcht1]="","",[Forms]![Ma_search2]![N_search]) & "*") AND ((Mid$(";" & [I1].[PRMF] & ";",[S1].[num],1))=';') AND ((Mid$(";" & [I1].[PRMF] & ";",[S2].[num],1))=';') AND (([S1].[num]+1)<[S2].[num]) AND ((InStr(1,Mid$(";" & [I1].[PRMF] & ";",[S1].[num]+1,[S2].[num]-[S1].[num]-1),";"))=0));
txN_searcht1 above is another textbox for optional search entry. It calls a module where: getA1A2A3 is called
This is the module:
Code:
Public Function getA1A2A3(A1 As String, A2, A3) As String
If IsNull(A2) And IsNull(A3) Then getA1A2A3 = A1: Exit Function
Dim S As String
S = A1 & IIf(Len(A1) < 4, " ", ", ")
If IsNull(A3) Then
S = S & A2
Else
S = S & IIf(IsNull(A2), "", A2 & ", ") & A3
End If
getA1A2A3 = S
End Function
Here is an e.g of code in action:
POSTCODE(TEXT)
OP11 9UV
PRMF(memo)
Mossbank Primary School;Northlea Auto Point;Post Office;The Old School Centre;1;2;3
STRD(text)
(NULL)
STR(text)
Jenson Park
LOCDD(text)
Pentwith
LOCD(text)
Mile Haven
PTN(text)
Chester
CNT(text)
(NULL)
WCD(text)
866YT
This will result:
Postcode... Expr1................................................ Expr2... and so on
OP11 9UV Mossbank Primary School, Jenson Park Pentwith, Mile Haven
OP11 9UV Northlea Auto Point, Jenson Park Pentwith, Mile Haven
the rest will be similar the numbers at the end will be like so:
OP11 9UV 1 Jenson Park Pentwith, Mile Haven
OP11 9UV 2 Jenson Park Pentwith, Mile Haven
OP11 9UV 3 Jenson Park Pentwith, Mile Haven
i.e. no comma.
The main thing that is slowing it down is table: index the greater the amount of records it holds the slower the query runs any way to speed up process?
Any help very much appreciated, thank in advance,
M-.