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


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

Re: Help needed to write a qury

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!k3g2000prl.googlegroups.com!not-for-mail
From Dinesh <dinesht15@gmail.com>
Newsgroups comp.databases.ms-sqlserver
Subject Re: Help needed to write a qury
Date Tue, 26 Apr 2011 01:58:26 -0700 (PDT)
Organization http://groups.google.com
Lines 37
Message-ID <4e344968-e681-4abf-82e6-98ce6490a65c@k3g2000prl.googlegroups.com> (permalink)
References <95071489-1d30-4d5b-b075-aa465d7b654c@x37g2000prb.googlegroups.com> <Xns9ED1DE4FB98A7Yazorman@127.0.0.1> <4db4fdc3$0$41114$e4fe514c@news.xs4all.nl> <Xns9ED268284C5CYazorman@127.0.0.1> <4db5449d$0$32470$e4fe514c@news.xs4all.nl> <Xns9ED29DD33336EYazorman@127.0.0.1> <Xns9ED29DEAC6336Yazorman@127.0.0.1> <4676728c-12fd-401a-87d3-c9011880b425@bl1g2000vbb.googlegroups.com> <Xns9ED2ED1394084Yazorman@127.0.0.1>
NNTP-Posting-Host 203.123.184.122
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1303808306 4572 127.0.0.1 (26 Apr 2011 08:58:26 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 26 Apr 2011 08:58:26 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info k3g2000prl.googlegroups.com; posting-host=203.123.184.122; posting-account=c-1-ygoAAAC0kYqwlHCH29-kttFWYQF3
User-Agent G2/1.0
X-HTTP-UserAgent Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729),gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.databases.ms-sqlserver:219

Show key headers only | View raw


On Apr 26, 2:18 am, Erland Sommarskog <esq...@sommarskog.se> wrote:
> Fred. (ghrno-goo...@yahoo.com) writes:
> > The WITH clause works in a manner similar to a derived table, but sets
> > up the syntax so that it can be referenced more than once.  In this
> > instance it allows the table to joined to itself rather than a second
> > derivation of itself as would happen using the derived table syntax.
>
> Correct. This is known as a CTE, Common Table Expression.
>
> > The OVER construct (just what is the syntax term?) specifies that row
> > numbering restarts for each new value of the field specified in
> > PARTITION BY, with the rows arranged within each partition as
> > specified in ORDER BY.
>
> Correct. It's called the OVER clause.
>
> > Do you know if the engine optimizes by indexing the WITH table on the
> > PARTTION field and the field receiveing row_number()?
>
> The CTE is purely logical. Some products are able to materialize the CTE as
> optimisation, but SQL Server is not. Thus, in some cases it can be better
> to use a temp table to hold the numbering.
>
> Lennart mention LEAD and LAG. They are also subclauses within OVER. They
> are not available in SQL Server currently, but in products that have LAG and
> LEAD, this can be written as a straight query without a self-join.
>
> --
> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>
> Links for SQL Server Books Online:
> SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
> SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Thanks a lot for all.

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


Thread

Help needed to write a qury Dinesh <dinesht15@gmail.com> - 2011-04-24 10:26 -0700
  Re: Help needed to write a qury "Fred." <ghrno-google@yahoo.com> - 2011-04-24 12:27 -0700
  Re: Help needed to write a qury Erland Sommarskog <esquel@sommarskog.se> - 2011-04-24 21:51 +0200
    Re: Help needed to write a qury Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-25 06:50 +0200
      Re: Help needed to write a qury Erland Sommarskog <esquel@sommarskog.se> - 2011-04-25 10:14 +0200
        Re: Help needed to write a qury Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-25 11:52 +0200
          Re: Help needed to write a qury Erland Sommarskog <esquel@sommarskog.se> - 2011-04-25 15:30 +0200
            Re: Help needed to write a qury Erland Sommarskog <esquel@sommarskog.se> - 2011-04-25 15:31 +0200
              Re: Help needed to write a qury Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-25 16:29 +0200
              Re: Help needed to write a qury "Fred." <ghrno-google@yahoo.com> - 2011-04-25 11:41 -0700
                Re: Help needed to write a qury Erland Sommarskog <esquel@sommarskog.se> - 2011-04-25 23:18 +0200
                Re: Help needed to write a qury Dinesh <dinesht15@gmail.com> - 2011-04-26 01:58 -0700
    Re: Help needed to write a qury "Fred." <ghrno-google@yahoo.com> - 2011-04-25 06:28 -0700
    Re: Help needed to write a qury Lennart Jonsson <erik.lennart.jonsson@gmail.com> - 2011-04-25 17:44 +0200
      Re: Help needed to write a qury Erland Sommarskog <esquel@sommarskog.se> - 2011-05-25 00:01 +0200
        Re: Help needed to write a qury Lennart Jonsson <erik.lennart.jonsson@gmail.com> - 2011-05-25 21:15 +0200
  Re: Help needed to write a qury --CELKO-- <jcelko212@earthlink.net> - 2011-05-26 06:19 -0700

csiph-web