Re: SELECT 42 AS a, a AS b FROM system.iota
- From: Luc Van der Veurst <dba_azvub@xxxxxxxxxxx>
- Date: 13 Feb 2008 15:14:04 GMT
dtmackenzie <david.mackenzie@xxxxxxxxxxxx> wrote:
Yes, that's what I thought, but by reducing an example, it can
become unclear what you want to achieve. Your question is
kind of ambiguous : it can be interpreted as "can I give an item
in the select list the same name as the name of a column", while you
mean "can I make a reference to an item in the select list further in the
query by using the name I gave it" :-).
What you want doesn't work in ASE (spid is a columnname of sysprocesses) :
select spid as a, a as b from sysprocesses;
Msg 207, Level 16, State 4
Server 'DSP_ST_1_b', Line 1
Invalid column name 'a'.
Luc.
Hello Luc, the ambiguity didn't occur to me, probably because in ADS
it is unambiguous, but I see that you understand now what I meant.
However, I don't understand why Michael's example works in ASE - if
spid is a column of sysprocesses then I would expect an error already
with "SELECT 42 AS spid...".
No, because you can indeed give the column a name in the result
set equal to the name of an existing column.
What you can't do is giving 2 columns the same name, so
select suid as spid, spid from sysprocesses
doesn't work :
Msg 7348, Level 15, State 1
Server 'DSP_ST_1_a', Line 1
Select expression results in more than one column having same name. Column
name 'spid' is specified more
than once
but
select suid as spid, spid as suid from sysprocesses
works :-).
Of course this is confusing. the 'as <name>' is only used in
the result set (to be used by the program who executed the
query) and nowhere else, that's why your example doesn't work.
when I execute :
select suid as spid, spid as suid from sysprocesses
where spid = 54
I get :
spid suid
----------- ------
4979 54
Luc.
Anyway, if what I want doesn't work in ASE either then I don't suppose.
there's much chance of Sybase supporting it in ADS, even though I
still believe that it works in SQL Anywhere (or at least used to when
I last worked with it, about 8 years ago using PowerBuilder). I can
understand this in a way - it's not quite so easy because e.g.
circular definitions have to be avoided. Nevertheless it's a pity and
rather inconvenient - I'd still be interested to hear what the SQL
standard has to say about it.
In any case, thanks for taking an interest!
David
- References:
- SELECT 42 AS a, a AS b FROM system.iota
- From: dtmackenzie
- Re: SELECT 42 AS a, a AS b FROM system.iota
- From: mpeppler@xxxxxxxxxxx
- Re: SELECT 42 AS a, a AS b FROM system.iota
- From: Luc Van der Veurst
- Re: SELECT 42 AS a, a AS b FROM system.iota
- From: dtmackenzie
- Re: SELECT 42 AS a, a AS b FROM system.iota
- From: Luc Van der Veurst
- Re: SELECT 42 AS a, a AS b FROM system.iota
- From: dtmackenzie
- SELECT 42 AS a, a AS b FROM system.iota
- Prev by Date: Re: SELECT 42 AS a, a AS b FROM system.iota
- Next by Date: Re: SELECT 42 AS a, a AS b FROM system.iota
- Previous by thread: Re: SELECT 42 AS a, a AS b FROM system.iota
- Next by thread: Re: SELECT 42 AS a, a AS b FROM system.iota
- Index(es):
Relevant Pages
|