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

  • SEARCH
  • Home
  • 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 765677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:55:28+00:00 2026-05-14T16:55:28+00:00

I am comparing some CHAR data in a where clause in my sql like

  • 0

I am comparing some CHAR data in a where clause in my sql like this,

where PRI_CODE < PriCode

The problem I am having is when the CHAR values are of different lengths.
So if PRI_CODE = ‘0800’ and PriCode = ’20’ it is returning true instead of false.

It looks like it is comparing it like this

'08' < '20' 

instead of like

'0800' < '20'

Does a CHAR comparison start from the Left until one or the other values end?

If so how do I fix this?

My values can have letters in it so convering to numeric is not an option.

  • 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-14T16:55:29+00:00Added an answer on May 14, 2026 at 4:55 pm

    It’s not comparing ’08’ with ’20’, it is, as you expect, comparing ‘0800’ with ’20’.

    What you don’t seem to expect, however, is that ‘0800’ (the string) is indeed less than ’20’ (the string).

    If converting it to numerics for a numeric comparison is out of the question, you could use the following DB2 function:

    right ('0000000000'||val,10)
    

    which will give you val padded on the left with zeroes to a size of 10 (ideal for a CHAR(10), for example). That will at least guarantee that the fields are the same size and the comparison will work for your particular case. But I urge you to rethink how you’re doing things: per-row functions rarely scale well, performance-wise.

    If you’re using z/OS, you should have a few DBAs just lying around on the computer room floor waiting for work – you can probably ask one of them for advice more tailored to your specific application 🙂

    One thing that comes to mind in the use of an insert/update trigger and secondary column PRI_CODE_PADDED to hold the PRI_CODE column fully padded out (using the same method as above). Then make sure your PriCode variable is similarly formatted before executing the select ... where PR_CODE_PADDED < PriCode.

    Incurring that cost at insert/update time will amortise it over all the selects you’re likely to do (which, because they’re no longer using per-row functions, will be blindingly fast), giving you better overall performance (assuming your database isn’t one of those incredibly rare beasts that are written more than read, of course).

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

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can change setting in CFadministrator > settings > Request… May 14, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer I think I've answered my own question, and I believe… May 14, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer Sounds like a bug to me. I suggest filing it… May 14, 2026 at 10:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.