Link to home
Start Free TrialLog in
Avatar of FamousMortimer
FamousMortimerFlag for United States of America

asked on

SQL - Show Quantity on last line of Item Group

Hi Experts,  consider this example

declare @t table
  (
     ItemNumber varchar(8),
     EntryDate  date,
     Qty        int
  )

insert into @t
values      ('abc',
             '8/1/2013',
             100),
            ('def',
             '8/3/2013',
             200),
            ('def',
             '8/5/2013',
             200),
            ('def',
             '8/7/2013',
             200),
            ('ghi',
             '8/4/2013',
             500),
            ('ghi',
             '8/5/2013',
             500)

select *
from   @t 
 

Open in new window



Desired Output is as follows...

ItemNumber|Quantity
ABC               |100
DEF                |NULL
DEF                |NULL
DEF                |200
GHI                |NULL
GHI                |500

Thanks
-FM
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FamousMortimer

ASKER

I was hoping there was some other way than joining it to itself because it was a massive query but i used a cte to keep it a bit cleaner.

Thanks