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


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

Select last column amongst group of columns where value>0

Newsgroups microsoft.public.sqlserver.programming
Date 2016-12-01 08:21 -0800
Message-ID <4e3f4200-45fa-45f6-9ec7-196f884c8d7c@googlegroups.com> (permalink)
Subject Select last column amongst group of columns where value>0
From Mary Phelps <icanhelp33@gmail.com>

Show all headers | View raw


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. 

Back to microsoft.public.sqlserver.programming | Previous | NextNext 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