SQL Server stored procedure / cursor -
i wanted know if possible in sql server:
my table looks this:
create table membership ( memebership_id int identity(1,1)primary key not null, membership_expiry_date datetime, member_account_balance money, member_blacklisted bit ,--(0 no, 1 yes) customer_id int not null, last_payment datetime )
i wanted know if possible use stored procedure or without cursor inside of change member_blacklisted
column if last_payment
more 6 months date has inserted e.g.
declare @memberid int,@date datetime
my attempt far:
declare @memberid int,@date datetime -- declaring cursor. declare c_expired_penalty_blacklist cursor ( select membership ) -- open cursor declared. open c_expired_penalty_blacklist fetch next c_expired_penalty_blacklist @memberid,@date while @@fetch_status = 0 begin if @date > datepart(month,getdate()+6) begin update membership set member_blacklisted = 1 memebership_id = @memberid end fetch next c_expired_penalty_blacklist @memberid,@date end close c_expired_penalty_blacklist deallocate c_expired_penalty_blacklist
try this:
update membership set member_blacklisted = 1 last_payment < dateadd(month, -6, getdate())
Comments
Post a Comment