?
Solved

m_strFilter question.

Posted on 2003-02-26
5
Medium Priority
?
409 Views
Last Modified: 2013-11-20
I have 2 indexes STKI and DOCI. I need to Filter for the 2nd index only,ie all records with DOCN (2nd param) regardless of the STK (1st param). What do I substitute for the m_strSTKParam.  I have tried inserting ALL and
*, and other combinations.  MSDN Documentation does not address this specifically. If I only put the second parameter in the strFilter and not the rest it also doesn't work because the recordset has 2 parameters so the strFilter is supposed to have both Parameters. The question is what do I put for the 1st parameter?

 DET.m_strSTKParam="";
 DET.m_strDOCNParam=m_getdoc;
 DET.m_strFilter="STK= ?  AND DOCN= ?";
 DET.Requery();

(If I I specify a value for the 1st and 2nd Param then there is no problem so that is not the question.)

Thanks.


0
Comment
Question by:binstar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:zfact
ID: 8031517
Hi binstar,
Try doing this.

if you want only the sencond parametsr, then set the filter only for the second parameter like below, it will work.

DET.m_strSTKParam="";
DET.m_strDOCNParam=m_getdoc;
DET.m_strFilter="DOCN= " + m_getdoc;
DET.Requery();

Try it, All the best.
Zfact
0
 
LVL 22

Expert Comment

by:ambience
ID: 8032549
or you can try the following

DET.m_strSTKParam="%";
DET.m_strDOCNParam=m_getdoc;
DET.m_strFilter="STK LIKE ?  AND DOCN= ?";

not sure but maybe ..
0
 

Author Comment

by:binstar
ID: 8076889
I think both of these approaches should work, but they are not.  I know that if I specify a value in single quotes for the second parameter only it works
ie DET.m_strFilter="DOCN='123'"
But why is it not working with the placeholder?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1200 total points
ID: 8726177
The answer to this question is quite simple.   When the first param is empty, the resulting WHERE clause is invalid.  The SQL Server will see something like:

     SELECT * FROM MyTable WHERE STK=  AND DOCN= 'someValue'

which is obviously an error.  The simple and intiutive solution is to not use the STK=? parm when you don't want to use STK in the search criteria!

But there is another workaround if you can't figure out how to do that.  Use

     SELECT * FROM MyTable WHERE STK=STK  AND DOCN= 'someValue'

I see no way to do that with query parameters, because the driver will treat it like a quoted string.  But parameters are just a pain to work with anyway.  Just get rid of the parameterss altogetherand  format the m_strFilter string as desired:

        if (  m_getStk !=  "" ) {
                DET.m_strFilter.Format( "STK= '%s'  AND DOCN= '%s'", m_getStk, m_getdoc );
        }
        else {
                DET.m_strFilter.Format( "DOCN= '%s'", m_getdoc );
                // alternative, foolish but functional
                // DET.m_strFilter.Format( "STK=STK  AND  DOCN= '%s'", m_getdoc );
                //
        }

-- Dan
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question