Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6691149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:43:06+00:00 2026-05-26T05:43:06+00:00

I am using this statement in part of my application, its generated. The LIKE

  • 0

I am using this statement in part of my application, its generated. The LIKE ‘%%’ are empty only because no search parameter was sent to it, so its pulling in all results.

I am still a novice to the whole database thing and was wondering if there are any tips for improving my statement?

I’m sure it looks horrible but please go easy on me!

Update: I am mostly looking to get better performance from this. I already used the DB2 adviser and created the keys it said I should make. That helped some but its still slower than I had hoped.

Thank you.

SELECT * FROM 
(
    SELECT rownumber() OVER (ORDER BY pgmajdsc, item) AS ROW_NUM, 
    line, item, pgmajdsc, manufacturer 
    FROM 
    (
        SELECT iline AS line, iitem AS item, pgmajdsc, ldesc AS manufacturer 
        FROM itemmast 
        LEFT JOIN itemweb on iline=line and iitem=item 
        JOIN linemst ON iline=lline 
        LEFT JOIN custord ON opline=iline AND opitem=iitem AND opcust='1234' 
        LEFT JOIN cartwdtl ON cwline=iline and cwitem=iitem and cwusr='foo' AND cwcust='1234' 
        LEFT JOIN itematr ON iline=ialine AND iitem=iaitem 
        LEFT JOIN prodgrp ON iaclass=pgclass 
        WHERE ico = 01 
        AND iecomm = 'Y' 
        AND (UPPER(ITEMDESC) LIKE '%%' OR UPPER(PRODDESC) LIKE '%%' OR 
            LINE LIKE '%%' OR UPPER(MFGNAME) LIKE '%%' OR ITEM LIKE '%%' OR 
            PRODNAME LIKE '%%' OR IDESC1 LIKE '%%' OR IDESC2 LIKE '%%' OR 
            IMFGNO LIKE '%%' OR IITEM LIKE '%%')
    ) AS TEMP
) AS ROW_NUM  
WHERE ROW_NUM BETWEEN 0 AND 25 
ORDER BY pgmajdsc, item
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:43:07+00:00Added an answer on May 26, 2026 at 5:43 am

    Assuming you are using a parameter for the like clauses the first thing I would change is that statement to check if it is null, it will avoid all the other comparisons. The other change would be to remove the nesting. You can achieve the same effect (I think anyway) by using the Fetch first clause.

    NOTE: This is untested as I do not have a db in front of me at the moment, but I am pretty sure it will work.

    SELECT rownumber() OVER (ORDER BY pgmajdsc, item) AS ROW_NUM, 
           iline AS line, iitem AS item, pgmajdsc, ldesc AS manufacturer 
    FROM itemmast 
       LEFT JOIN itemweb on iline=line and iitem=item 
       JOIN linemst ON iline=lline 
       LEFT JOIN custord ON opline=iline AND opitem=iitem AND opcust='1234' 
       LEFT JOIN cartwdtl ON cwline=iline and cwitem=iitem and cwusr='foo' AND cwcust='1234' 
       LEFT JOIN itematr ON iline=ialine AND iitem=iaitem 
       LEFT JOIN prodgrp ON iaclass=pgclass 
    WHERE ico = 01 
      AND iecomm = 'Y' 
      AND (parameter IS NULL 
           OR (UPPER(ITEMDESC) LIKE '%'||parameter||'%' 
           OR UPPER(PRODDESC) LIKE '%'||parameter||'%'
           OR LINE LIKE '%'||parameter||'%' 
           OR UPPER(MFGNAME) LIKE '%'||parameter||'%' 
           OR ITEM LIKE '%'||parameter||'%' 
           OR PRODNAME LIKE '%'||parameter||'%' 
           OR IDESC1 LIKE '%'||parameter||'%' 
           OR IDESC2 LIKE '%'||parameter||'%' 
           OR IMFGNO LIKE '%'||parameter||'%' 
           OR IITEM LIKE '%'||parameter||'%') )
    ORDER BY ROW_NUM, pgmajdsc, item
    FETCH FIRST 25 ROWS ONLY
    

    EDIT: Another thought is unless you actually need the row number you can leave that out and just do your order by like so:

    SELECT iline AS line, iitem AS item, pgmajdsc, ldesc AS manufacturer 
    FROM itemmast 
       LEFT JOIN itemweb on iline=line and iitem=item 
       JOIN linemst ON iline=lline 
       LEFT JOIN custord ON opline=iline AND opitem=iitem AND opcust='1234' 
       LEFT JOIN cartwdtl ON cwline=iline and cwitem=iitem and cwusr='foo' AND cwcust='1234' 
       LEFT JOIN itematr ON iline=ialine AND iitem=iaitem 
       LEFT JOIN prodgrp ON iaclass=pgclass 
    WHERE ico = 01 
      AND iecomm = 'Y' 
      AND (parameter IS NULL 
           OR (UPPER(ITEMDESC) LIKE '%'||parameter||'%' 
           OR UPPER(PRODDESC) LIKE '%'||parameter||'%'
           OR LINE LIKE '%'||parameter||'%' 
           OR UPPER(MFGNAME) LIKE '%'||parameter||'%' 
           OR ITEM LIKE '%'||parameter||'%' 
           OR PRODNAME LIKE '%'||parameter||'%' 
           OR IDESC1 LIKE '%'||parameter||'%' 
           OR IDESC2 LIKE '%'||parameter||'%' 
           OR IMFGNO LIKE '%'||parameter||'%' 
           OR IITEM LIKE '%'||parameter||'%') )
    ORDER BY pgmajdsc, item
    FETCH FIRST 25 ROWS ONLY
    

    I do not know how much a hit on performance is on calculating rownumber, but if you do not need it, no need to return it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I have a problem when trying to execute this update statement (below) using C#
I'm using Python 2.5. I'm trying to use this 'with' statement. from __future__ import
Am working on web based Job search application using Lucene.User on my site can
Part I I am working on a web application that instead of using a
I'm using prepared statements and MySQLi, and am currently getting this error. PHP Catchable
Using this question as the base is there an alogrithm or coding example to
Using this file as source, I have a situation where I need to retrieve
Using this answer , I created a sample localized app. My question is, is
Using this: Can I use Facebook's fb:friend-selector in an iframe? I created a multi-friend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.