vijay11
asked on
Can some one write this with out cursor
Can some one write this sql with out cursor
declare @state_id int , @num varchar(100), @all varchar(2000)
declare cur_state cursor for
select state_id
from state
open cur_state
while (1=1)
begin
fetch cur_inst into @inst_id
if @@fetch_status<>0 break
declare cur_acct cursor for
select ltrim(rtrim(data))
from view_values v
where v.type='P'
and v.status='A'
and v.name='Acc'
and v.state_id=@state_id
select @all =''
open cur_acct
while (1=1)
begin
fetch cur_acct into @num
if @@fetch_status <> 0 break
select @all = @all + ' / ' + @num
end
close cur_acct
deallocate cur_acct
if @all <> ''
begin
select @all = substring(@all, 4,len(@all) - 3)
update country
set acct_no = @all
where state_id=@state_id
end
end
close cur_state
deallocate cur_state
end
This should be compatible ith sql 2000 also
Thanks in advance
declare @state_id int , @num varchar(100), @all varchar(2000)
declare cur_state cursor for
select state_id
from state
open cur_state
while (1=1)
begin
fetch cur_inst into @inst_id
if @@fetch_status<>0 break
declare cur_acct cursor for
select ltrim(rtrim(data))
from view_values v
where v.type='P'
and v.status='A'
and v.name='Acc'
and v.state_id=@state_id
select @all =''
open cur_acct
while (1=1)
begin
fetch cur_acct into @num
if @@fetch_status <> 0 break
select @all = @all + ' / ' + @num
end
close cur_acct
deallocate cur_acct
if @all <> ''
begin
select @all = substring(@all, 4,len(@all) - 3)
update country
set acct_no = @all
where state_id=@state_id
end
end
close cur_state
deallocate cur_state
end
This should be compatible ith sql 2000 also
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Kevin,
>>In case your other question is going down a similar<<
I think you mean questions, here is a third duplicate question:
https://www.experts-exchange.com/questions/27028021/can-some-one-help-with-this-logic.html
Anthony
>>In case your other question is going down a similar<<
I think you mean questions, here is a third duplicate question:
https://www.experts-exchange.com/questions/27028021/can-some-one-help-with-this-logic.html
Anthony
Open in new window