All Forums General
kkaya 2 posts Joined 08/13
05 Jul 2014
A sımple questıon

Hi guys,
how can i provide this sql to return the B column value as 3. I want to use the column K in the current row although it is also in table.
 
In fact I will use the solution in a recursive query. In recursive query i want to use the new value of related column not the previous one for the next iteration.
 
Thanks.
 
SEL SUBSTR(K,1,3) K , LENGTH(K) B
FROM
(
SELECT 'KKKKK' K,'MMMM'M
)Q

dnoeth 4628 posts Joined 11/04
05 Jul 2014

Simply name it differently.
When there's a column and an alias with the same name the parser assumes the query it's referencing the column and not the alias.

SEL SUBSTR(K,1,3) newK , LENGTH(newK) B
FROM
(
SELECT 'KKKKK' K,'MMMM'M
)Q

 

Dieter

kkaya 2 posts Joined 08/13
05 Jul 2014

I have to use the same name  for the new column value. Cant i distinguish the new column K and "Q.K" with something like "this.K" :). Is there a function to handle this case.
 
SEL SUBSTR(K,1,3) K , LENGTH(this.K) B
FROM
(
SELECT 'KKKKK' K,'MMMM'M
)Q

dnoeth 4628 posts Joined 11/04
05 Jul 2014

No, you can't do that.
But why do you think you need it?
Within a recursive query you can simply apply the new name and still have the output name as defined.

Dieter

You must sign in to leave a comment.