sql - How to assign a variable different values based on a column cell values -
i need loop through rows , following:
if date_deleted null set @form = '01' else @form = '02'
currently returning form = 01 only.
thank you!
select @checkdate = [date_deleted] executive__vehicles (state = 'nc') if ( @checkdate null ) begin set @form = '01' end else begin set @form = '02' end
you need load results executive_vehicles temp table , loop through them 1 one set.
create table #temptable1(iid int identity(1,1),date_deleted datetime) insert #temptable1 select [date_deleted] executive__vehicles (state = 'nc') declare @countrows int declare @checkdate datetime declare @toprow int set @countrows =(select count(*) #temptable1) while @countrows>0 begin set @toprow = (select top 1 iid #temptable1) set @checkdate = (select top 1 date_deleted #temptable1) if ( @checkdate null ) begin set @form = '01' end else begin set @form = '02' end delete #temptable1 iid=@toprow set @countrows = (select count(*) #temptable1) set @checkdate = null end
editted add identity column date_deleted same multiple rows , delete delete of them.
Comments
Post a Comment