Stef Merlijn
asked on
SQL where only part of string is selected
Hi,
I would like to create a SQL where I only select the unique first character of the field CompanyName.
So the SQL should be adjusted a little bit.
Select Distinct CompanyName from Companies
Result should be
A
G
H etc.
The second thing I have to do is checking if a caption of a button is within the query-result and if so enable it.
procedure TFBedrijven.FilterknoppenB ijwerken;
var i : Integer;
begin
for i := 0 to ComponentCount-1 do
if (Components[i] is TdxBarButton) then
TdxBarButton(Components[i] ).Enabled := TdxBarButton(Components[i] ).Caption >> IN Queryresult(A,G,H);
end;
Thank you for your help.
Stef
I would like to create a SQL where I only select the unique first character of the field CompanyName.
So the SQL should be adjusted a little bit.
Select Distinct CompanyName from Companies
Result should be
A
G
H etc.
The second thing I have to do is checking if a caption of a button is within the query-result and if so enable it.
procedure TFBedrijven.FilterknoppenB
var i : Integer;
begin
for i := 0 to ComponentCount-1 do
if (Components[i] is TdxBarButton) then
TdxBarButton(Components[i]
end;
Thank you for your help.
Stef
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found one..
SELECT Distinct MID(Bedrijven.Bedrijfsnaam ,1,1) FROM Bedrijven Order by 1;
SELECT Distinct MID(Bedrijven.Bedrijfsnaam
hmm, guess acces has similar function, not in mind yet
about the array,
you could declare the array also like
Buttons : array[ord('A')..ord('Z')] of TdxBarButton;
disable would the be
for i := ord('A') to ord('Z') do
Bottons[i].enabled := false;
iteration then
while not dataset.eof do
Buttons[ord(dataset.fields [0].asstri ng[1])].en abled := true;
meikl ;-)
about the array,
you could declare the array also like
Buttons : array[ord('A')..ord('Z')] of TdxBarButton;
disable would the be
for i := ord('A') to ord('Z') do
Bottons[i].enabled := false;
iteration then
while not dataset.eof do
Buttons[ord(dataset.fields
meikl ;-)
oops, you found one :-))
not seen your comment before
not seen your comment before
ASKER
Where do I place the init array?
Buttons[0] := mbA
Buttons[1] := mbB
etc.
Buttons[0] := mbA
Buttons[1] := mbB
etc.
ASKER
One more question:
I also have a button with 0 (zero) which is used for all numeric values.
Ho to add that to the array etc.?
I also have a button with 0 (zero) which is used for all numeric values.
Ho to add that to the array etc.?
>Where do I place the init array?
best in the oncreate-event of your form,
this must be done only once
>also have a button with 0 (zero)
bad, in this case an array is useless or we have some empty slots
chars 0-9 are ords 48-57
chars A-Z are ords 65-90
seven slots would be unused (58-64) chars :;<=>?@
i think about that
meikl ;-)
best in the oncreate-event of your form,
this must be done only once
>also have a button with 0 (zero)
bad, in this case an array is useless or we have some empty slots
chars 0-9 are ords 48-57
chars A-Z are ords 65-90
seven slots would be unused (58-64) chars :;<=>?@
i think about that
meikl ;-)
ASKER
This code is looping forever. But we are getting there.
while not dataset.eof do
Buttons[ord(dataset.fields [0].asstri ng[1]) - 64].enabled := true
while not dataset.eof do
Buttons[ord(dataset.fields
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So only the part with the 0 (zero) value remains.
The rest is working perfectly. Thanks a lot.
Stef
The rest is working perfectly. Thanks a lot.
Stef
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes that seems to be the solution if not the 0 (zero) should be set to True when any numeric value is the first character.
So 0,1,2,3,4,5,6,7,8 and 9.
So 0,1,2,3,4,5,6,7,8 and 9.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well Meikl, you earned your point with ease.
Thank you.
Stef
Thank you.
Stef
glad you got it work :-))
good luck again
meikl ;-)
good luck again
meikl ;-)
ASKER
Just some small adjustment:
The offset must be 64 after all.
// Deze procedure zet de verschillende filterknoppen aan waarvoor
// daadwerkelijk gegevens beschikbaar zijn.
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' SELECT Distinct MID(Bedrijven.Bedrijfsnaam ,1,1) AS BeginLetter FROM Bedrijven Order by 1 ');
Open;
end;
for i := 0 to 26 do
MyButton[i].enabled := false;
DM.QAlgemeenGebruik.First;
while not DM.QAlgemeenGebruik.Eof do
begin
if DM.QAlgemeenGebruik.Fields [0].asstri ng[1] in ['0'..'9'] then //change here
MyButton[0].enabled := true
else
MyButton[Ord(DM.QAlgemeenG ebruik.Fie lds[0].ass tring[1]) - 64].enabled := true; //offset should be 64
DM.QAlgemeenGebruik.Next; //missed this
end;
The offset must be 64 after all.
// Deze procedure zet de verschillende filterknoppen aan waarvoor
// daadwerkelijk gegevens beschikbaar zijn.
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' SELECT Distinct MID(Bedrijven.Bedrijfsnaam
Open;
end;
for i := 0 to 26 do
MyButton[i].enabled := false;
DM.QAlgemeenGebruik.First;
while not DM.QAlgemeenGebruik.Eof do
begin
if DM.QAlgemeenGebruik.Fields
MyButton[0].enabled := true
else
MyButton[Ord(DM.QAlgemeenG
DM.QAlgemeenGebruik.Next; //missed this
end;
>The offset must be 64 after all.
oops, my mistake, sorry :-))
oops, my mistake, sorry :-))
ASKER