Work on every record sql server -
so, new microsoft sql server.
i have table name login credentials
id | name | l_date | status 1 | aa |1.2.2017 | active
so have find ones have difference of 3 months in date current date , set them inactive.
example: above l_date 1.2.2017
, current 12.09.2017
, there 3 month gap , set inactive.
what tried.
use databasename go create procedure dbo.datediffer declare @lastchangedate date declare @current date declare @datediffernce int declare @mycursor cursor; declare @myfield ; begin set @mycursor = cursor select * dbo.table_name open @mycursor fetch next @mycursor @myfield while @@fetch_status = 0 begin set @current=getdate() set @datediffernce=datediff(mm, @lastchangedate , @current) //something here , cant seem l_date , make algo on , change status. fetch next @mycursor @myfield end; close @mycursor ; deallocate @mycursor; end; go
any kind of appreciated , thank you.
when using sql server, if find using cursors you're doing wrong!
update [login credentials] set status = 'inactive' datediff(mm,l_date,getdate())>=3
Comments
Post a Comment