Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

range where isn't working

Posted on by Microsoft Employee

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: range where isn't working

    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!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: range where isn't working

    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?

  • Suggested answer
    Thomas Franz Profile Picture
    Thomas Franz 1,105 on at
    RE: range where isn't working

    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.

  • L Vail Profile Picture
    L Vail 65,271 on at
    RE: range where isn't working

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: range where isn't working

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: range where isn't working

    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
    Community Member Microsoft Employee on at
    RE: range where isn't working

    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.

  • L Vail Profile Picture
    L Vail 65,271 on at
    RE: range where isn't working

    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

  • Suggested answer
    L Vail Profile Picture
    L Vail 65,271 on at
    RE: range where isn't working

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans