ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Using ESQL to select and insert multiple rows.

Post new topic  Reply to topic
 Using ESQL to select and insert multiple rows. « View previous topic :: View next topic » 
Author Message
Fresher_Newbie
PostPosted: Wed Jun 24, 2015 3:24 am    Post subject: Using ESQL to select and insert multiple rows. Reply with quote

Novice

Joined: 24 Jun 2015
Posts: 13

Hello folks,

I need to select multiple rows from one table and insert the selected rows into another table in the same database. I have the Orcacle/SQL query for that, and is as follows:

Code:
INSERT INTO "ESB"."REQ_COUNT" (MESSAGE_FLOW, NO_OF_REQUESTS, START_TIME, END_TIME)
SELECT message_flow, count(*) as No_of_Requests, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + interval '15' minute
FROM "ESB"."MESSAGE_LOG"
WHERE log_point = 'ClientRequest' AND process_timestamp BETWEEN CURRENT_TIMESTAMP AND CURRENT_TIMESTAMP + interval '15' minute
GROUP BY message_flow;


"ESB" is the schema name.
"REQ_COUNT" and "MESSAGE_LOG" are the table names.

I'm really new to WMB/IIB and not adept with ESQL. Could any of please help me translate this SQL query into its equivalent ESQL code? Thanks!

P.S: I did try a lot, but didn't really come up with a syntactically right ESQL code. I'm finding this a bit complex at this stage.
Back to top
View user's profile Send private message
nelson
PostPosted: Wed Jun 24, 2015 4:11 am    Post subject: Reply with quote

Partisan

Joined: 02 Oct 2012
Posts: 313

Hi,

Here is described how SELECT works (and samples):
https://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak05620_.htm

Code:
SELECT A FROM Database.Datasource.SchemaName.Table AS A


and here how INSERT works (and samples):
https://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak05050_.htm

Code:
-- Declare variables to hold the data source, schema, and table names
-- and set their default values
DECLARE Source CHARACTER 'Production';
DECLARE Schema CHARACTER 'db2admin';
DECLARE Table  CHARACTER 'DynamicTable1';

-- Code which calculates their actual values comes here

-- Insert the data into the table
INSERT INTO Database.{Source}.{Schema}.{Table} (Name, Value) values ('Joe', 12.34);
Back to top
View user's profile Send private message
Fresher_Newbie
PostPosted: Wed Jun 24, 2015 10:59 pm    Post subject: Reply with quote

Novice

Joined: 24 Jun 2015
Posts: 13

Thanks Nelson, but since the query involves the usage of the count(*), and GROUP BY functions, the normal select and insert isn't ideal.

I explored the PASSTHRU function, but I'm just not able to get it's syntax right. I'll look further into it. Sucks to be a beginner.
Back to top
View user's profile Send private message
mgk
PostPosted: Thu Jun 25, 2015 1:46 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Unfortunately, the ESQL INSERT does not support a multi-row insert so you will have to insert each one individually. An alternative would be to call a stored procedure to do this INSERT instead. A PASSTHRU could work, but a SP will probably be better. Also, I'm not sure why you need the GROUP BY clause given that the target is another table and not a report...

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
View user's profile Send private message
fjb_saper
PostPosted: Thu Jun 25, 2015 4:24 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Not sure what kind of result you'd expect....
Shouldn't the where clause say
Code:
process_timestamp between CURRENT_TIMESTAMP - INTERVAL 15 MINUTES and CURRENT_TIMESTAMP
??
Don't know what you'd have recorded in your DB between now and the future...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Fresher_Newbie
PostPosted: Thu Jun 25, 2015 10:44 pm    Post subject: Reply with quote

Novice

Joined: 24 Jun 2015
Posts: 13

@fjb_saper - Oh yes, my bad. It should be the way you've mentioned it.

@mgk - Thanks, I'll look into doing it the way you suggested.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Using ESQL to select and insert multiple rows.
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.