| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

03-23-10, 10:37
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
|
cast to varchar
|
|
On v9.7:
db2 "select varchar(count(0)) from (select count(c1) from test) as tmp"
1
-----------
1
1 record(s) selected.
On v8.2:
db2 "select varchar(count(0)) from (select count(c1) from test) as tmp"
SQL0440N No authorized routine named "VARCHAR" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884
I need to cast the result of the following query into a varchar:
db2 "select count(0) from (select count(c1) from test) as tmp"
v8 doesn't accept integer as an input to varchar(). Is there a way to accomplish this on v8?
|
|

03-23-10, 10:40
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Try CAST(blah as VARCHAR(88))
|
|

03-23-10, 10:42
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
|
|
By the way, "select '1' from sysibm.sysdummy1" will also work, as the query always returns 1...
|
|

03-23-10, 10:45
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Quote:
Originally Posted by n_i
Try CAST(blah as VARCHAR(88))
|
Make it CAST(CAST(blah as CHAR(88)) as VARCHAR(88))
|
|

03-23-10, 10:51
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
Thanks, Nick. Using two CAST worked:
db2 "select cast(cast(count(0) as char(88)) as varchar(88)) from (select count(c1) from test) as tmp"
1
----------------------------------------------------------------------------------------
1
1 record(s) selected.
I'll try using sysibm.sysdummy1
|
|

03-23-10, 11:36
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
Originally Posted by db2girl
I need to cast the result of the following query into a varchar:
db2 "select count(0) from (select count(c1) from test) as tmp"
|
why even run a query? the answer is always going to be 1
|
|

03-23-10, 11:55
|
|
Registered User
|
|
Join Date: Nov 2005
Location: IL
Posts: 554
|
|
Shh, Bella is booking over time 
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
DB2 v9.1.0.2 os 5.3.0.0
|
|

03-23-10, 12:02
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
Quote:
Originally Posted by r937
why even run a query? the answer is always going to be 1
|
This is not my query and I'm still trying to understand the purpose of count(0)... doing multiple things at the same time so had no time to really think about your response to my other posting  but I will.
Could you please explain why the following query (attaching it here) returns 0.
|
Last edited by db2girl; 03-23-10 at 13:43.
|

03-23-10, 12:06
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
Originally Posted by db2girl
Could you please explain why the following query (attaching it here) returns 0.
|
most likely it is because the subquery returned no rows -- try running the subquery by itself
by the way, apologies to n_i, who had the same answer as i did in post #3 (i.e. it's always going to return 1)
|
|

03-23-10, 12:06
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
Or how to replace "SELECT COUNT(0) AS "COUNT" " without changing the purpose of it. This count(0) is causing the query to fail with sql0901n which is what I'm trying to resolve.
|
|

03-23-10, 12:07
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
change it to SELECT COUNT(*) ...
|
|

03-23-10, 13:28
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
I think logically the entire query is equivalent to something like
Code:
count (distinct POL_STATUS_CD) from < that table> where <those conditions
By the way, since the subquery is an outer join, the subtraction one of the SUM()s can be problematic, because both values could be null.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|