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


Groups > microsoft.public.sqlserver.programming > #31313

Re: Select last column amongst group of columns where value>0

X-Received by 10.237.32.236 with SMTP id 99mr4288389qtb.24.1482540050596; Fri, 23 Dec 2016 16:40:50 -0800 (PST)
X-Received by 10.157.17.3 with SMTP id g3mr1312642ote.8.1482540050548; Fri, 23 Dec 2016 16:40:50 -0800 (PST)
Path csiph.com!weretis.net!feeder6.news.weretis.net!news.glorb.com!p16no2069730qta.1!news-out.google.com!u18ni18862ita.0!nntp.google.com!75no3122050ite.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups microsoft.public.sqlserver.programming
Date Fri, 23 Dec 2016 16:40:50 -0800 (PST)
In-Reply-To <4e3f4200-45fa-45f6-9ec7-196f884c8d7c@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=65.48.139.193; posting-account=tN54agoAAACNjDnBJfs5in-APU29Pkzy
NNTP-Posting-Host 65.48.139.193
References <4e3f4200-45fa-45f6-9ec7-196f884c8d7c@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <8b8cc9e2-c714-4a46-bd50-bf1212a08527@googlegroups.com> (permalink)
Subject Re: Select last column amongst group of columns where value>0
From maizesheng@gmail.com
Injection-Date Sat, 24 Dec 2016 00:40:50 +0000
Content-Type text/plain; charset=UTF-8
Xref csiph.com microsoft.public.sqlserver.programming:31313

Show key headers only | View raw


On Thursday, December 1, 2016 at 12:21:44 PM UTC-4, Mary Phelps wrote:
> Here is data in my table
> 
> SiteId  Week1A  Week1B  Week2A  Week2B  Week3A  Week3B  Week4A Week4B  Week5A  Week5B
> 101      0        8        7      9      0       6       0       9      0        9
> 288      8        8        0      7      0       7       0       8      6        6
> 468      1        8        6      9      8       6       0       9      0        9
> 768      0        8        0      7      0       7       6       8      0        6
> 
> I want a query that will look at all week1a,week2a,week3a,week4a,week5a and so forth
> then figure out which is the last column which has value greater than 0 for example SiteId 101 It is Week2A. SiteId 288 it is Week5A. SiteId 468 week3A.
> 
> then after the last column is figured out sum up values of weeks remaing after that so for example siteid101 last column is week2a so i want a sum of week3b,week4b and week5b.

Your presentation is not clear. For example row SiteID:101 Week5B:9 is greater than > 0 and if we assume that order starts from Week1A then it would be the last column with a value greater than zero.

Back to microsoft.public.sqlserver.programming | Previous | NextPrevious in thread | Find similar


Thread

Select last column amongst group of columns where value>0 Mary Phelps <icanhelp33@gmail.com> - 2016-12-01 08:21 -0800
  Re: Select last column amongst group of columns where value>0 --CELKO-- <jcelko212@earthlink.net> - 2016-12-02 10:07 -0800
  Re: Select last column amongst group of columns where value>0 maizesheng@gmail.com - 2016-12-23 16:40 -0800

csiph-web