web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

range where isn't working

(0) ShareShare
ReportReport
Posted on by

I'm trying to use a range where clause but I always get all rows back in the window.  I've used SQL Profiler to see what's happening and I don't see the where clause being added.  Here's what I'm doing:

range clear table TBLNAME;

range table TBLNAME where physicalname('field_name' of table TBLNAME) + " LIKE '%" + strVal + "%'";

fill window WINDOW_NAME;

The help file is pretty limited and I've found a lot of examples that use the above.  What am I missing?

*This post is locked for comments

  • Suggested answer
    L Vail Profile Picture
    65,271 on at

    Hi,

    I would make sure my pass-through SQL was coming back correctly (like display it in a warning box) and then I would use the result directly in Management Studio to make sure it's returning the result set I want. Sometimes I've found an error in my select statement that caused it to return the wrong rows.

    Kind regards,

    Leslie

  • L Vail Profile Picture
    65,271 on at

    Hi Larry,

    I do not see any problems with the syntax of your code. On what object have you attached your code? Is it on the change script of strVal, or something else?

    Kind regards,

    Leslie

  • Community Member Profile Picture
    on at

    I'm new to Dex and confused by your reply. I'm using the range where, not SQL pass through. I'm using SQL profiler to see what Dex is doing in terms of creating the SQL. In profiler is can see the select statement but it doesn't include the where clause.

  • Community Member Profile Picture
    on at

    Does it matter where the request comes from?  I have used the debugger to break in the above code. I've confirmed that the sting has the value I desire. I've checked the err value after the range where and the fill window. It's always 0. Not sure what else to try.

  • Community Member Profile Picture
    on at

    One more note. I have used the debugger to confirm that the where clause is correct. The problem is that the where clause isn't making it to SQL which is confirmed using SQL profiler.

  • L Vail Profile Picture
    65,271 on at

    Hi Larry,

    I created a form with a scrolling window. The scrolling window used the PM_Vendor_MSTR table. I created the field (L)String2 in the header of the window containing the scrolling window. I attached the code to the changed event of the

    (L)String1 field.  Here is the code I used:

    range clear table PM_Vendor_MSTR;

    range table PM_Vendor_MSTR where physicalname('Vendor ID' of table PM_Vendor_MSTR) + " LIKE '%" + '(L) String2' + "%'";

    fill window WhereTest_Scroll;

    That's all there was to my test and it worked perfectly. I looked at SQL Profiler and could see my WHERE clause.

    SQL-Trace.png

    What is different in your code? Are you opening a different table or changing windows or anything like that. It seems something is happening that causes it to lose your WHERE restriction.

    Would you consider posting your actual code?

    Kind regards,

    Leslie

    Kind regards,

    Leslie

  • Suggested answer
    Thomas Franz Profile Picture
    1,105 on at

    I don't see any fundamental issues with this approach. Are you sure that the TBLNAME table is the "LinkTable" for the WINDOW_NAME scrolling window? Can you populate the window without the range where statement? One other thought, it is best practice to wrap the "strVal" variable with the SQL_FormatStrings function, apostrophe's and other special characters in these variables can cause problems in the where clauses.

  • Community Member Profile Picture
    on at

    Thanks for the feedback thus far.  I've tried all the suggestions so far and none have produced the desired results.  TBLNAME is a custom table that I've created in my solution.  I can see the table and the stored procs have been created and I've loaded the table with data.  The table has a total of 10 keys.  I have logic that determines which key to use.  SQL profiler confirms that the proper key is being used (proper stored proc being selected) depending on the sort option selected.  I've simplified the test to a simple range start/end combination.  The tests always result in the proper stored proc being called but there are never any parameters passed.  This is the same behavior with the where test.  Do I need to do something special for the keys?

  • Verified answer
    Community Member Profile Picture
    on at

    I found the answer thanks to this post on tek-tips.com (www.tek-tips.com/viewthread.cfm).  The golden nugget was the mention of a procedure creating it's own table buffer.  I am in fact using a procedure.  When I added the in parameter and passed the table from the form event handler it worked!  Thanks again for your input!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans