Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL query question

$
0
0

Hi,


 I came across a problem that I can't find a solution to and maybe one of you could help me with that.

I have a table that records Inventory on a nightly basis across our locations and it records any items that fall on zero stock.

I've to now show a count of 'days on zerostock' for items that has been on zero stock for any number of consecutive days.

Here is my sample table.

Company    Item    Qty           Asof
US                  A      0            6/20/2013
US                  A      0            6/19/2013
US                  A      0            6/15/2013
US                  A      0            6/14/2013
US                  BB    0            6/20/2013
US                  BB    0            6/19/2013
MUC               A      0            6/20/2013
MUC               A      0            6/17/2013
MUC               A      0            6/16/2013
MUC               BB    0            6/19/2013
MUC               BB    0            6/18/2013
MUC               BB    0            6/17/2013
MUC               BB    0            6/10/2013

The extra column needs to show values as per below. (Remember : Its by Item and by Company )

Company  Item    Qty     Asof            Days on Zerostock
US              A          0   6/20/2013                 2
US              A          0   6/19/2013                 1
US              A          0   6/15/2013                 2
US              A          0   6/14/2013                 1
US             BB         0   6/20/2013                 2
US             BB         0   6/19/2013                 1
MUC          A           0   6/20/2013                 1
MUC          A           0   6/17/2013                 2
MUC          A           0   6/16/2013                 1
MUC          BB         0   6/19/2013                 3
MUC          BB         0   6/18/2013                 2 
MUC          BB         0   6/17/2013                 1
MUC          BB         0   6/10/2013                 1

Can you help me with providing a sql query of how to popluate this new column.

Any help is appreciated.

Thanks,
Devang.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>