what is the underlying data type of ICRTDT?
and what are you attempting to do?
wouldn't using the DATE functions... be more appropriate?
DATE/TIMESTAMP/DAY/MONTH/Y
which version and O/S of DB2/UDB are you using?
Main Topics
Browse All Topicsany way i can around this query
select ICRTDT ,
substr (cast (int( ICRTDT)+20000000 as char (8)), 1, 4) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 5, 2) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 7, 2) as NEWICRTDT
from v_aaa_item
where NEWICRTDT = '2001-06-07'
fetch first 10 rows only;
select ICRTDT , substr (cast (int( ICRTDT)+20000000 as char (8)), 1, 4) || '-' || substr (cast (int( ICRTDT)+20000000 as char (8)), 5, 2) || '-' || substr (cast (int( ICRTDT)+20000000 as char (8)), 7, 2) as NEWICRTDT from v_aaa_item where NEWICRTDT = '2001-06-07' fetch first 10 rows only
SQL0206N "NEWICRTDT" is not valid in the context where it is used.
SQLSTATE=42703
SQL0206N "NEWICRTDT " is not valid in the context where it is used.
thanks
Bobby
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
HI KDO
its version 8.2
SELECT * FROM
(
select ICRTDT,
cast (
(cast ((ICRTDT/10000+2000) as char(4)) || '-' ||
cast (MOD(ICRTDT/100, 100) as char(2)) || '-' ||
cast (MOD(ICRTDT, 100) as char(2))) as date) as NEWICRTDT
from v_aaa_item
) AS a
where NEWICRTDT = '2001-06-07'
fetch first 10 rows only;
--------------------------
SELECT * FROM ( select ICRTDT, cast ( (cast ((ICRTDT/10000+2000) as char(4)) || '-' || cast (MOD(ICRTDT/100, 100) as char(2)) || '-' || cast (MOD(ICRTDT, 100) as char(2))) as date) as NEWICRTDT from v_aaa_item ) AS a where NEWICRTDT = '2001-06-07' fetch first 10 rows only
SQL0440N No authorized routine named "MOD" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884
Thanks,
Bobby
MOD() should convert the decimal to integer. weird.
Just for grins, try this one:
SELECT * FROM
(
select ICRTDT,
cast (
(cast ((ICRTDT/10000+2000) as char(4)) || '-' ||
cast (MOD(INT(ICRTDT/100), 100) as char(2)) || '-' ||
cast (MOD(INT(ICRTDT), 100) as char(2))) as date) as NEWICRTDT
from v_aaa_item
) AS a
where NEWICRTDT = '2001-06-07'
fetch first 10 rows only;
--------------------------
SELECT * FROM ( select ICRTDT, cast ( (cast ((ICRTDT/10000+2000) as char(4)) || '-' || cast (MOD(INT(ICRTDT/100), 100) as char(2)) || '-' || cast (MOD(INT(ICRTDT), 100) as char(2))) as date) as NEWICRTDT from v_aaa_item ) AS a where NEWICRTDT = '2001-06-07' fetch first 10 rows only
ICRTDT NEWICRTDT
--------- ----------
SQL0180N The syntax of the string representation of a datetime value is
incorrect. SQLSTATE=22007
SQL0180N The syntax of the string representation of a datetime value is incorrect.
Explanation:
The string representation of a date, time, or timestamp value
does not conform to the syntax for the specified or implied data
type.
The statement cannot be processed.
User Response:
Ensure that the syntax of the date, time, or timestamp value
conforms to the syntax for its data type. If the string is not
intended to be a date, time, or timestamp value, ensure that when
used, it does not imply that data type.
Federated system users: the problem might be due to a date/time
representation problem at the data source. If the reason is
unknown, isolate the problem to the data source failing the
request problem determination guide and examine the date/time
representation restrictions for that data source.
sqlcode : -180
sqlstate : 22007
Business Accounts
Answer for Membership
by: KdoPosted on 2006-05-24 at 12:53:31ID: 16755338
Hi bobby2929,
A couple of ways. Perhaps the easiest is to treat the list as a subquery.
SELECT * FROM
(
select ICRTDT ,
substr (cast (int( ICRTDT)+20000000 as char (8)), 1, 4) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 5, 2) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 7, 2) as NEWICRTDT
from v_aaa_item
) AS a
where NEWICRTDT = '2001-06-07'
fetch first 10 rows only;
If performance is an issue, you can also repeat the computing in the WHERE clause.
select ICRTDT ,
substr (cast (int( ICRTDT)+20000000 as char (8)), 1, 4) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 5, 2) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 7, 2) as NEWICRTDT
from v_aaa_item
where '2001-06-07' =
substr (cast (int( ICRTDT)+20000000 as char (8)), 1, 4) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 5, 2) || '-' ||
substr (cast (int( ICRTDT)+20000000 as char (8)), 7, 2)
fetch first 10 rows only;
Note however, that your math appears off. You probably don't want to add 20000000 to the month and day values.
Good Luck!
Kent