Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

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

asked 04 Oct '13, 12:03

mfkpie8's gravatar image

mfkpie8
273667075
accept rate: 12%

edited 04 Oct '13, 12:49

What do you expect anyone to do now? - Your questions incomplete postings are really becoming a nuisance here, at least in my usually humble opinion:(

(04 Oct '13, 12:27) Volker Barth
Replies hidden

Please help me to correction ,I uploaded the pictures of the error thanks,So I'll pay attention next time under my ability of expression

(04 Oct '13, 12:51) mfkpie8
Comment Text Removed

Please post proper questions. If you don't know how to phrase them in English, just write them in your own language.

I fear you mis-understand the purposes of groups like these - they aren't here to do your work for you. If you have something you can't make work - explain what the problem is, what you have tried to do to solve it yourself, exactly what error you are getting and when, together with the version of the software, OS etc that you are using.

If you just post some code and say "error loop" - you are expecting someone else to set up a test environment, run your code etc just to find out what the problem is - not many people have the time or inclination to do that. You may do better to employ a consultant with the appropriate skills or use SAP's consulting services.

permanent link

answered 04 Oct '13, 12:44

Justin%20Willey's gravatar image

Justin Willey
7.6k137179249
accept rate: 20%

edited 04 Oct '13, 12:46

Please help me to correction ,I uploaded the pictures of the error thanks,So I'll pay attention next time under my ability of expression

(04 Oct '13, 12:51) mfkpie8

I think the problem that you are having is that you are mixing WATCOM SQL with TSQL. The WHILE ... LOOP statement is WATCOM SQL whereas the TSQL variant of a WHILE statement does not use the LOOP keyword. You have been using TSQL procedures so you need to use a WHILE statement - i.e. remove the LOOP and END LOOP and add in a BEGIN ... END.

OR alternatively, switch to using WATCOM SQL.

HTH

permanent link

answered 04 Oct '13, 13:07

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297
accept rate: 41%

WATCOM SQL so I should go to where to find relevant learning materials

(04 Oct '13, 13:48) mfkpie8

My answer contains the two relevant links for the two variants of the WHILE statement. You can find all of the documentation for SQL Anywhere at http://dcx.sybase.com/index.html

(04 Oct '13, 13:51) Mark Culp

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

permanent link

answered 04 Oct '13, 13:12

Justin%20Willey's gravatar image

Justin Willey
7.6k137179249
accept rate: 20%

Unable to execute the statement stop i is not var

(04 Oct '13, 13:49) mfkpie8
Replies hidden

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

(04 Oct '13, 16:38) Justin Willey
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

(10 Oct '13, 07:17) mfkpie8
Replies hidden

(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.

(10 Oct '13, 08:13) Mark Culp

@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.

(10 Oct '13, 08:14) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×90

question asked: 04 Oct '13, 12:03

question was seen: 2,665 times

last updated: 10 Oct '13, 08:14