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
Field created from case statement / SQL0312
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
deanclowe@nf.sympatico.ca
*nix forums beginner


Joined: 18 Feb 2005
Posts: 2

PostPosted: Fri Feb 18, 2005 6:30 pm    Post subject: Re: Field created from case statement / SQL0312 Reply with quote

Thanks Serge,

That's exactly what I was looking for.

Dean
Back to top
Serge Rielau
*nix forums Guru


Joined: 29 Apr 2005
Posts: 1583

PostPosted: Fri Feb 18, 2005 11:56 am    Post subject: Re: Field created from case statement / SQL0312 Reply with quote

deanclowe@nf.sympatico.ca wrote:
Quote:
Hi I have a query that is trying to use a field that is created "AS"
based on a case statement like this:

SELECT
CASE
WHEN IPOVH = 'Y' THEN '01'
WHEN IPHSI = 'Y' THEN '02'
WHEN IPVIS = 'Y' THEN '03'
ELSE ' '
END AS CRIT_CODE,

Func_Retreive_GenericTableDescription('CRIT', CRIT_CODE)
AS STAT_DESC

FROM ..... and so on...

But it doesn't seem to want to let me use CRIT_CODE in my function
call. (This runs on iSeries V5R3 and is part of a stored procedure).
Same thing happens when I try to use CRIT_CODE in a join. Is there
some way I can use the result of this case statement in
functions/joins?

Currently I get error SQL0312 Variable CRIT_CODE not defined or not
usable.

You cannot correlate within the select list. Conceptually all columns

get generated in parallel. Try a nested select instead:
SELECT CRIT_CODE,
Func_Retreive_GenericTableDescription('CRIT', CRIT_CODE)
AS STAT_DESC
FROM (SELECT CRIT_CODE FROM .....) AS X

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Back to top
deanclowe@nf.sympatico.ca
*nix forums beginner


Joined: 18 Feb 2005
Posts: 2

PostPosted: Fri Feb 18, 2005 3:29 am    Post subject: Field created from case statement / SQL0312 Reply with quote

Hi I have a query that is trying to use a field that is created "AS"
based on a case statement like this:

SELECT
CASE
WHEN IPOVH = 'Y' THEN '01'
WHEN IPHSI = 'Y' THEN '02'
WHEN IPVIS = 'Y' THEN '03'
ELSE ' '
END AS CRIT_CODE,

Func_Retreive_GenericTableDescription('CRIT', CRIT_CODE)
AS STAT_DESC

FROM ..... and so on...

But it doesn't seem to want to let me use CRIT_CODE in my function
call. (This runs on iSeries V5R3 and is part of a stored procedure).
Same thing happens when I try to use CRIT_CODE in a join. Is there
some way I can use the result of this case statement in
functions/joins?

Currently I get error SQL0312 Variable CRIT_CODE not defined or not
usable.
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:26 am | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Select statement Shamna Sybase 0 Mon Sep 17, 2007 6:03 am
No new posts ECPG (usage of simple select statement) Jasbinder Bali PostgreSQL 0 Fri Jul 21, 2006 3:28 am
No new posts Invalid syntax with STD() function when more than one fie... William Bronsema MySQL 1 Thu Jul 20, 2006 2:18 pm
No new posts Help with attempting to add time to a MySQL field from PHP? bobmct PHP 3 Tue Jul 18, 2006 5:43 pm
No new posts tremendous upturn on pink sheets, overwhelmingly importan... Larry Hurd devel 0 Mon Jul 17, 2006 4:50 pm

Personal Loans | Bankruptcy | Car Finance | Mobile Phones | Loans
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.1201s ][ Queries: 20 (0.0473s) ][ GZIP on - Debug on ]