Here is my script:
declare @CashGiving table
(
giftid char(10),
gifteffdat datetime,
giftacctdv char(6)
col int
)
insert into @CashGiving
(giftid,gifteffdat,giftacctdv,col)
select giftid,gifteffdat,giftacctdv,row_number() over(partition by giftid order by giftid) as col
from gifts with (nolock)
where gifttype in ('g','b','y')
order by giftid
The query produces data such as
giftid gifteffdat giftacctdv col First
001 7/1/2006 12 1 Y
001 7/15/2006 12 2 N
001 7/15/2006 14 3 Y
003 7/22/2009 17 1 Y
003 7/30/2006 25 2 N
For each giftid, if an Id appears more than once they get a new row number. I want to create a "First" column that sets to a 'Y' whenever
a. If the ID appears for the first time
b. If the ID remains the same but the giftacctdv changes
declare @CashGiving table
(
giftid char(10),
gifteffdat datetime,
giftacctdv char(6)
col int
)
insert into @CashGiving
(giftid,gifteffdat,giftacctdv,col)
select giftid,gifteffdat,giftacctdv,row_number() over(partition by giftid order by giftid) as col
from gifts with (nolock)
where gifttype in ('g','b','y')
order by giftid
The query produces data such as
giftid gifteffdat giftacctdv col First
001 7/1/2006 12 1 Y
001 7/15/2006 12 2 N
001 7/15/2006 14 3 Y
003 7/22/2009 17 1 Y
003 7/30/2006 25 2 N
For each giftid, if an Id appears more than once they get a new row number. I want to create a "First" column that sets to a 'Y' whenever
a. If the ID appears for the first time
b. If the ID remains the same but the giftacctdv changes