Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1122

Re: Combine Multiple Rows into one (denormalize) explain the SQL

From "Bob Barrows" <reb01501@NOyahooSPAM.com>
Newsgroups comp.databases.ms-sqlserver
Subject Re: Combine Multiple Rows into one (denormalize) explain the SQL
Date 2012-06-14 10:57 -0400
Organization A noiseless patient Spider
Message-ID <jrcu4k$urk$1@dont-email.me> (permalink)
References <765c1eed-5e88-49d0-bc04-ea6ca4031ccd@i19g2000yqn.googlegroups.com>

Show all headers | View raw


bill wrote:
<snip>
> I have definitely not seen the part at the end where the sub-query is
> aliased as g, and then a parenthesized letter (y) is put at the end
>
> It appears that g.y becomes a column, but the syntax is confusing to
> me.
>
> Thanks,
>
> Bill
>
<snip>
>  (
> SELECT DISTINCT ',' + CAST(SubID AS VARCHAR(11))
> FROM @Sample AS s
> WHERE s.ID = i.ID
> ORDER BY ',' + CAST(SubID AS VARCHAR(11))
> FOR XML PATH('')
> ) AS g (y)

A derived table is aliased with g, and the name of the column in the derived
table is aliased with y. Notice that the column name was not provided in the
derived table select statement. Even if it was, it would be overridden by
the alias.

Similar syntax can be seen with the CREATE VIEW statement:
CREATE VIEW ViewName (colname1,...,colnameN) AS
SELECT ...

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Combine Multiple Rows into one (denormalize) explain the SQL bill <billmaclean1@gmail.com> - 2012-06-13 15:48 -0700
  Re: Combine Multiple Rows into one (denormalize) explain the SQL "Bob Barrows" <reb01501@NOyahooSPAM.com> - 2012-06-14 10:57 -0400
  Re: Combine Multiple Rows into one (denormalize) explain the SQL Erland Sommarskog <esquel@sommarskog.se> - 2012-06-14 21:49 +0200
    Re: Combine Multiple Rows into one (denormalize) explain the SQL bill <billmaclean1@gmail.com> - 2012-06-18 12:33 -0700

csiph-web