Filter on ADO recordset

Set rsColumns = cn.OpenSchema(adSchemaColumns)

How to retrieve recordset that the first two charactors of table's name not including "vw_" at such as "vw_Test"?
leeannAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sudhi022299Commented:
if that supports specifying a query then you can do it.
Does it ?

Regards,
Sudhi.
0
TimCotteeHead of Software ServicesCommented:
Here is an example of using the filter property of the recordset. You may need to fiddle with it a little though.

Dim cn As New ADODB.Connection
Dim rsColumns As New ADODB.Recordset
cn.ConnectionString = "PROVIDER=MSDASQL;driver={SQL Server};server=osiuk009;uid=;pwd=;database=pilot;"
cn.Open
Set rsColumns = cn.OpenSchema(adSchemaColumns)
rsColumns.Filter = "TABLE_NAME Like 'vw%'"
With rsColumns
    .MoveFirst
    Do
        List1.AddItem rsColumns!TABLE_NAME
        .MoveNext
    Loop Until .EOF
End With
rsColumns.Close
cn.Close
Set rsColumns = Nothing
Set cn = Nothing
0
leeannAuthor Commented:
TimCotte,

As I know, the recordset has only three operators: ">", "<", and "LIKE". There is no "NOT LIKE" operator on the recordset. My problem is to how to get recordset that doesn't include name like "VW_".
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

sudhi022299Commented:
I think the recordset filter property supports "NOT LIKE". Check it out.

Is it not possible for you to specify the query to get those records ?

Regards,
Sudhi.
0
TimCotteeHead of Software ServicesCommented:
I agree that the recordset filter doesn't seem to support NOT LIKE, however if you want to exclude 'vw%' then the following will do that:

rsColumns.Filter = "TABLE_NAME < 'vw' OR TABLE_NAME >= 'vx'"
0
Antonio_PsCommented:
Try this Query to your RecordSet Source:

"Select X From TABLE WHERE X NOT IN (SELECT X FROM TABLE WHERE X LIKE 'vw%')
0
leeannAuthor Commented:
Sorry, I tried the following way but failed.
Set rsColumns = cn.OpenSchema(adSchemaColumns)
    rsColumns.Filter = "Select TABLE_NAME WHERE TABLE_NAME NOT IN (SELECT TABLE_NAME WHERE TABLE_NAME LIKE 'vw%')"
0
leeannAuthor Commented:
Using OpenSchema(adSchemaColumns) method of the ADO connection will receive all tables the user accessable as well as views. I want a solution to only receive tables not including views which names like "VW_" in the recordset. Do you have any suggestion?
0
leeannAuthor Commented:
Using OpenSchema(adSchemaColumns) method of the ADO connection will receive all tables the user accessable as well as views. I want a solution to only receive tables not including views which names like "VW_" in the recordset. Do you have any suggestion?
0
sudhi022299Commented:
i think that the query "Select X From TABLE WHERE X NOT IN (SELECT X FROM TABLE WHERE X LIKE 'vw%' " should not be set for the filter propery. It should rather be passed to the open method. Comments please !

Regards,
Sudhi.
0
TimCotteeHead of Software ServicesCommented:
sudhi, I agree, you cannot use such complex queries in the filter property. Leeann, have you tried my >= <= selection criteria? It works for me!
0
leeannAuthor Commented:
Hi TimCottee,

It's amazing! Your codes work correctly. Would you please tell me how your codes solve my problem? Thank you very much!!!
0
TimCotteeHead of Software ServicesCommented:
It works because if you think about what that statement is doing, you see that it is including all tables which are alphabetically < vw i.e. anything starting a,b,c,d... aa,ab,ac..va,vb,vc up to and including vu, or those which are alphabetically after vx inclusive. This is equivalent to the NOT Like operator but can be used in the filter property.
0
leeannAuthor Commented:
Thanks, TimCottee. I have increated the point to 100. Please lock this question.

By the way, do you think it is possible that the table name including more than two alphas could equal "vw"?  
0
TimCotteeHead of Software ServicesCommented:
No, it wouldn't match, 'vwaaa' is always greater than 'vw' and would be excluded no matter what. And 'vx' is always greater than 'vwZZZZZZ.....' no matter how many characters you use, or whatever they are.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leeannAuthor Commented:
How about others excluding "vw.." such as "mn..."?
0
TimCotteeHead of Software ServicesCommented:
leeann, if you mean that you want to have more than one criteria excluded then this will be difficult. There are restrictions on the filter property syntax which mean that the obvious extension of the logic used first time doesn't work. i.e you cannot apparently use (TABLE_NAME < 'vw' OR TABLE_NAME >= 'vx') AND (TABLE_NAME < 'mn' OR TABLE_NAME >= 'mo') because the filter property will not allow an AND operator to join to clauses already joined with an OR operator. I haven't been able yet to work out a statement which works logically given the restrictions placed by the filter property. If you really need to do this, then it would perhaps be better to look at an alternative method.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.