Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SUBSTR in WHERE clause SQl/DB2

Posted on 2011-09-13
5
Medium Priority
?
11,053 Views
Last Modified: 2012-05-12
Hi,
I am using SUBSTR in a WHERE clause in an SQL DB2.statement.
SYNTAX:

WHERE
substr(ldate,1,4) = substr(mdate,1,4)

I get the following error.
"SELECT - 0 row(s), 0.000 secs]  [Error Code: -440, SQL State: 42884]  DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884, SQLERRMC=SUBSTR;FUNCTION, DRIVER=3.57.82"

Is anyone familar with this?

Thanks in advance!



0
Comment
Question by:Mark1M
[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
 
LVL 24

Expert Comment

by:jimyX
ID: 36534036
What is the data type of ldate & mdate?
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36534188
just guessing, probably because substr doesn't work on dates.  Try casting/converting to a string before applying the substr function.
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36534208
WHERE
substr(cast(ldate as varchar(26)),1,4) = substr(cast(mdate as varchar(26)),1,4)
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 1000 total points
ID: 36535961
Hi Mark,

What's the data type of ldate and mdate?  If they are date and/or timestamp objects, you can use any of the built-in DB2 date functions to extract the portion of the data that you want.  

Since you're extracting 4 characters, I'll assume that you're comparing years.  In DB2, the equivalent SQL would be:

  WHERE year (ldate) = year (mdate)

And of course, if they are really strings, dqmq has posted a definitive answer.  :)


Good Luck,
Kent
0
 

Author Closing Comment

by:Mark1M
ID: 36536556
Kent & Everyone,
Thank you!
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

598 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