Filtering a table with an UNIQUEIDENTIFIER field

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Filtering a table with an UNIQUEIDENTIFIER field

Post by ads42 » Fri 10 Jan 2014 09:13

Hi,
I can't figure how to filer a table with an UNIQUEIDENTIFIER field.
Any expression sample for doing this stuff ? it seems that ising simply a string doesn't work.
Regards

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Filtering a table with an UNIQUEIDENTIFIER field

Post by AlexP » Fri 10 Jan 2014 12:35

Hello,

To filter data, you can use either local filtration

Code: Select all

  MSQuery1.KeyFields := 'f_uniqueidentifier';
  MSQuery1.Open;
  MSQuery1.Filter := 'f_uniqueidentifier like ''%d6658596%''';
  MSQuery1.FilterOptions := [foCaseInsensitive];
  MSQuery1.Filtered := True;
or use filtration on the server

Code: Select all

  MSQuery1.FilterSQL := 'f_uniqueidentifier like ''%d6658596%''';

ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Re: Filtering a table with an UNIQUEIDENTIFIER field

Post by ads42 » Wed 29 Jan 2014 09:11

Hi Alex,
sory haven't received notifications about reply.
In your sample code you use an integer as a unique identifier, but in my case it's something like :
7fcaf9b3-7256-4953-a0e0-0c6122b47660

Any idea ?

Regards

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Filtering a table with an UNIQUEIDENTIFIER field

Post by AlexP » Wed 29 Jan 2014 09:33

In my example, I use a string field as KeyFields (the LIKE operator is used with strings). Please provide your query example.

ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Re: Filtering a table with an UNIQUEIDENTIFIER field

Post by ads42 » Wed 29 Jan 2014 09:49

in my case 7fcaf9b3-7256-4953-a0e0-0c6122b47660 is a string field.
Should I use %d like in your sample ?
Can you change your code using my string ?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Filtering a table with an UNIQUEIDENTIFIER field

Post by AlexP » Thu 30 Jan 2014 11:59

The '%' symbol in the LIKE operator means that any sequence of symbols can be in this place, i.e., if you specify in the filter:

Code: Select all

filed_name like '%a0e0%'
then all strings containing 'a0e0' will be found. If you need an accurate search, you should use the following filter:

Code: Select all

filed_name = '7fcaf9b3-7256-4953-a0e0-0c6122b47660'

ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Re: Filtering a table with an UNIQUEIDENTIFIER field

Post by ads42 » Thu 30 Jan 2014 12:48

Thanks Alex.

Post Reply