Author |
Message
|
pdmenon |
Posted: Wed Feb 09, 2011 12:19 am Post subject: Using Counter Variable in Insert Statement |
|
|
 Voyager
Joined: 05 Apr 2010 Posts: 80
|
Dear Experts,
Can we use Counter Variables in Insert Statement like -->
Code: |
SET COUNTER =1;
WHILE (COUNTER <= FOR_COUNTER) DO
INSERT INTO Database.TBL_TableName(
Column1,
Column2)
Values (
Environment.EXTRACT.RECORD[COUNTER].Column1,
Environment.EXTRACT.RECORD[COUNTER].Column2,
)
END WHILE; |
When using above code i am getting Syntax error stating -->
Severity and Description Syntax error. Valid options include: ( |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Feb 09, 2011 12:24 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Where are you incrementing COUNTER? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
pdmenon |
Posted: Wed Feb 09, 2011 12:31 am Post subject: |
|
|
 Voyager
Joined: 05 Apr 2010 Posts: 80
|
My bad.. The code should be:
Code: |
SET COUNTER =1;
WHILE (COUNTER <= FOR_COUNTER) DO
INSERT INTO Database.TBL_TableName(
Column1,
Column2)
Values (
Environment.EXTRACT.RECORD[COUNTER].Column1,
Environment.EXTRACT.RECORD[COUNTER].Column2,
)
SET COUNTER = COUNTER + 1;
END WHILE;
|
|
|
Back to top |
|
 |
mgk |
Posted: Wed Feb 09, 2011 1:33 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
Can we use Counter Variables in Insert Statement like |
Yes you can use Counters in Insert statements, but only if the syntax for the Insert Statement is correct.
There were two errors in the code you posted. The correct code should be:
Code: |
INSERT INTO Database.TBL_TableName(
Column1,
Column2)
Values (
Environment.EXTRACT.RECORD[COUNTER].Column1,
Environment.EXTRACT.RECORD[COUNTER].Column2
); |
Can you spot the two differences?
Kind regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
pdmenon |
Posted: Wed Feb 09, 2011 1:37 am Post subject: |
|
|
 Voyager
Joined: 05 Apr 2010 Posts: 80
|
Dear mgk,
It was my typo. I have ' ;' at the end of insert statement and no extra comma after the column end. |
|
Back to top |
|
 |
fatherjack |
Posted: Wed Feb 09, 2011 1:58 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
pdmenon wrote: |
Dear mgk,
It was my typo. I have ' ;' at the end of insert statement and no extra comma after the column end. |
Of course. We should've guessed that. Now how many guesses at the real syntax error in your code do you think we should have? _________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
j.f.sorge |
Posted: Wed Feb 09, 2011 9:51 am Post subject: |
|
|
Master
Joined: 27 Feb 2008 Posts: 218
|
Anyways it will be better to make use of a REFERENCE variable and MOVE NEXTSIBLING until LASTMOVE is FALSE. _________________ IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
|