niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » IBM DB2
TO_CHAR(date-value, 'HH24') returns error: type, length or value of arg is incorrect (42815)
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
Mark Hansen
*nix forums beginner


Joined: 18 Feb 2005
Posts: 12

PostPosted: Fri Feb 18, 2005 3:49 pm    Post subject: TO_CHAR(date-value, 'HH24') returns error: type, length or value of arg is incorrect (42815) Reply with quote

I'm trying to convert some schema creation scripts that were
used on MS SQL Server to DB2 (v8.2) and have a problem with
the following select statement (snippet) used for a view:

SELECT
col1,
col2,
timestamp-col1,
TO_CHAR(timestamp-col1, 'HH24')
FROM ...

When creating the view that uses this statement, I get the following
error:

Quote:
SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.TO_CHAR" is incorrect. SQLSTATE=42815

I tried using 'HH24:MI:SS', but this didn't help. The documentation
on the TO_CHAR() function (and TIMESTAMP_FORMAT) don't show any
examples of a format that doesn't include all timestamp parts (date
and time). However, this column needs to get only the hour portion.

Is there a way to do this in DB2 SQL?

Thanks,

--
Mark Hansen
Sacramento, CA
Back to top
Mark Hansen
*nix forums beginner


Joined: 18 Feb 2005
Posts: 12

PostPosted: Fri Feb 18, 2005 4:18 pm    Post subject: Re: TO_CHAR(date-value, 'HH24') returns error: type, length or value of arg is incorrect (42815) Reply with quote

On 2/18/2005 08:49, Mark Hansen wrote:

Quote:
I'm trying to convert some schema creation scripts that were
used on MS SQL Server to DB2 (v8.2) and have a problem with
the following select statement (snippet) used for a view:

SELECT
col1,
col2,
timestamp-col1,
TO_CHAR(timestamp-col1, 'HH24')
FROM ...

When creating the view that uses this statement, I get the following
error:

SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.TO_CHAR" is incorrect. SQLSTATE=42815

I tried using 'HH24:MI:SS', but this didn't help. The documentation
on the TO_CHAR() function (and TIMESTAMP_FORMAT) don't show any
examples of a format that doesn't include all timestamp parts (date
and time). However, this column needs to get only the hour portion.

Is there a way to do this in DB2 SQL?

Thanks,


After some more research, I found I can do this:

SELECT
col1,
col2,
timestamp-col1,
CAST(HOUR(timestamp-col1) AS CHAR),
FROM ...

Thanks for reading,


--
Mark Hansen
Sacramento, CA
Back to top
Serge Rielau
*nix forums Guru


Joined: 29 Apr 2005
Posts: 1583

PostPosted: Fri Feb 18, 2005 4:29 pm    Post subject: Re: TO_CHAR(date-value, 'HH24') returns error: type, length or value of arg is incorrect (42815) Reply with quote

Mark Hansen wrote:
Quote:
I'm trying to convert some schema creation scripts that were
used on MS SQL Server to DB2 (v8.2) and have a problem with
the following select statement (snippet) used for a view:

SELECT
col1,
col2,
timestamp-col1,
TO_CHAR(timestamp-col1, 'HH24')
FROM ...

When creating the view that uses this statement, I get the following
error:

SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.TO_CHAR" is incorrect. SQLSTATE=42815
I tried using 'HH24:MI:SS', but this didn't help. The documentation
on the TO_CHAR() function (and TIMESTAMP_FORMAT) don't show any
examples of a format that doesn't include all timestamp parts (date
and time). However, this column needs to get only the hour portion.

Is there a way to do this in DB2 SQL?
db2 => values char(hour(current timestamp));


1
-----------
12

1 record(s) selected.


--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 3:07 am | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Postfix + MySQL error: very strange variable %s iWarior Postfix 0 Mon Aug 25, 2008 2:01 pm
No new posts ** Postfix error on console every minute or so ** ?? drywash Postfix 0 Fri Jul 04, 2008 8:49 pm
No new posts Postfix error bounce diwash Postfix 0 Fri Mar 28, 2008 3:37 am
No new posts I am getting following error in Aix 5.3 rockcharles1 AIX 0 Tue Aug 28, 2007 11:06 pm
No new posts postfix out of memory error - please help metind Postfix 0 Mon Sep 11, 2006 1:54 am

Libro arquitectura | MPAA | Home Equity Loan | Debt Consolidation | Remortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2643s ][ Queries: 16 (0.1395s) ][ GZIP on - Debug on ]