cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

loop error,pls

ximen
Participant
0 Likes
4,071
declare @product_code char(10),@rowNR int,@Mrow int
set     i=1
select product_code,row_number() over(order by parent_id) as rowNR,parent_id into #FT_1 from product_code where parent_id='cp'
//select * from #ft_1
//select @mrow=max(rowNR) from #ft_1 
//select @mrow      
while  i<=29 LOOP
    select @product_code=product_code from #ft_1 where i=rownr
select @product_code
set i=i+1
end loop

select * from #t1

error loop alt text

View Entire Topic
justin_willey
Participant
0 Likes

You have a syntax error because you are running a series statements without any separators. You need a semi-colon between separate statements eg:

declare @product_code char(10),@rowNR int,@Mrow int
set     i=1;
select product_code,row_number() over(order by parent_id) as rowNR,parent_id into #FT_1 from      product_code where parent_id='cp';
//select * from #ft_1
//select @mrow=max(rowNR) from #ft_1 
//select @mrow      
while  i<=29 LOOP
select @product_code=product_code from #ft_1 where i=rownr;
select @product_code;
set i=i+1;
end loop

also you haven't declared i

ximen
Participant
0 Likes

Unable to execute the statement stop i is not var

justin_willey
Participant
0 Likes

as I said, you need to declare i before you can use it.

ximen
Participant
0 Likes
declare @product_code char(10),@rowNR int,@Mrow int
declare i
set  i=1
select product_code,row_number() over(order by parent_id) as rowNR,parent_id into #FT_1 from      product_code where parent_id='cp'
//select * from #ft_1
//select @mrow=max(rowNR) from #ft_1 
//select @mrow      
while  i<=29 LOOP
select @product_code=product_code from #ft_1 where i=rownr;
select @product_code;
set i=i+1;
end loop

error for set i=1

MarkCulp
Participant
0 Likes

(a) Your "declare i" is an incomplete statement - it needs a type. You likely want "declare i int"

(b) Did you read Justin's and my answer? You are mixing WATCOM SQL with TSQL and therefore you need to pick one. You are not going to anywhere with fixing your problems if you don't.

VolkerBarth
Contributor
0 Likes

@mfkpie8: Have you read the answers by Justin and Mark? They clearly explain the problem (mixing T-SQL and Watcom-SQL syntax). And you are still mixing these dialects. Sigh.