Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
omega1983
Starting Member
40 Posts |
Posted - 2009-10-20 : 12:29:50
|
| I have a stored procedure as follows:ALTER PROCEDURE [Cash_Export] -- Add the parameters for the stored procedure here @BeginDate datetime, @EndDate datetime, @Division varchar(50)ASSELECT case when gifteffdat <@BeginDate then 'Y' else 'N' end as FIRST_TIME_DONOR,giftid,gifteffdat,divsionfrom giftswhere(gifteffdat >= @BeginDate and gifteffdat <= @EndDate)and giftdv = @DivisionI am trying to insert a 'Y' if the the individual is giving for the first time. Here is some sample dataFIRSTTIMEDONOR,giftid,gifteffdat,divsionN 1 1/1/2009 BusinessN 2 5/15/2009 EngineeringLets say ID#2 Engineering is giving for the first time, I want a 'Y' to appear under FIRSTTIMEDONOR. Since I am pulling only the @BeginDate and @EndDate, I would miss any first time gifts. Is there a way to show first time gifts in this example I have given |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-20 : 13:02:05
|
| [code]ALTER PROCEDURE [Cash_Export] -- Add the parameters for the stored procedure here@BeginDate datetime,@EndDate datetime,@Division varchar(50)ASSELECT case when giftbefore=0 then 'Y' else 'N' end as FIRST_TIME_DONOR,giftid,gifteffdat,divsionfrom gifts gcross apply (select count(*) as giftbefore from gifts where division= g.division and gifteffdat< g.gifteffdat) g1where(gifteffdat >= @BeginDate and gifteffdat <= @EndDate)and giftdv = @Division[/code] |
 |
|
|
|
|
|
|
|