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 » How to use Like clause with Values in passthru

Post new topic  Reply to topic
 How to use Like clause with Values in passthru « View previous topic :: View next topic » 
Author Message
mindspace
PostPosted: Tue Jan 22, 2013 8:38 am    Post subject: How to use Like clause with Values in passthru Reply with quote

Apprentice

Joined: 22 Jan 2013
Posts: 26

Hi

Currently we have an sql query where we are passing literals in passthru,, like below.

Declare key Character;( sample values will be like '12344+23243+%')
sqlstmt = SELECT XXX FROM Database.Schema.Tablename
WHERE coloumn LIKE ''' || character|| '''';
SET sqlResult = PASSTHRU(sqlStmt TO Database.dsnName);

Now requirement is to use parameters in above query so that at run time same SQL statement can be used with different data value.

I am aware of using of parameter markers in normal cases but never used them with LIKE
Please suggest me if use of parameter markers is possible in above query?
I tried couple of things but no use..
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Tue Jan 22, 2013 9:19 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

You do this like any other CHARACTER string in ESQL. Substitute values in building the string (ie. ' || ') as you would any other time. This is not difficult. You would have seen this in the training class. Have you attended the class?
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Tue Jan 22, 2013 9:23 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

As well, whether or not you can use a parameter marker (a "?") in the PASSTHRU statement depends entirely on what the database behind the connection accepts, because passthru does exactly what it says it does.

It takes the SQL statement and passes it through to the database for execution.
Back to top
View user's profile Send private message
mindspace
PostPosted: Tue Jan 22, 2013 8:09 pm    Post subject: Reply with quote

Apprentice

Joined: 22 Jan 2013
Posts: 26

lancelotlinc wrote:
You do this like any other CHARACTER string in ESQL. Substitute values in building the string (ie. ' || ') as you would any other time. This is not difficult. You would have seen this in the training class. Have you attended the class?


I tried couple of things.. like below

SET sqlStmt = 'SELECT XXX FROM Database.Schema.Table name

WHERE XXX = ? VALUES LIKE ''' || Character|| '''';
SET sqlResult = PASSTHRU(sqlStmt TO Database.dsnName);

SET sqlStmt = 'SELECT XXX FROM Database.Schema.Table name

WHERE XXX LIKE ? VALUES ( ''' || character|| ''')';
SET sqlResult = PASSTHRU(sqlStmt TO Database.dsnName);

But nothing works.. please advice the right way of using parameter markers..
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jan 22, 2013 8:46 pm    Post subject: Reply with quote

Grand High Poobah

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

have you tried
Code:
VALUES ({character variable name})

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mindspace
PostPosted: Tue Jan 22, 2013 10:14 pm    Post subject: Reply with quote

Apprentice

Joined: 22 Jan 2013
Posts: 26

fjb_saper wrote:
have you tried
Code:
VALUES ({character variable name})


Nope,.. this doesnt work...
Back to top
View user's profile Send private message
kash3338
PostPosted: Tue Jan 22, 2013 10:58 pm    Post subject: Reply with quote

Shaman

Joined: 08 Feb 2009
Posts: 709
Location: Chennai, India

This code should work out,

Code:

DECLARE sqlStmt CHARACTER;
DECLARE pattern CHARACTER '<LIKE_Pattern>';

SET sqlStmt = 'SELECT XXX FROM Database.Schema.Table name
WHERE XXX LIKE ?';

SET sqlResult = PASSTHRU(sqlStmt, pattern);
Back to top
View user's profile Send private message Send e-mail
adubya
PostPosted: Wed Jan 23, 2013 1:58 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

How about the following

Code:

DECLARE likeExpr CHAR 'like expression e.g. %TEST%';
SET sqlStmt = 'SELECT XXX FROM Schema.Table name WHERE XXX LIKE ?'; 
SET sqlResult = PASSTHRU(sqlStmt TO Database.dsnName VALUES (likeExpr));
Back to top
View user's profile Send private message Send e-mail
mindspace
PostPosted: Wed Jan 23, 2013 6:51 am    Post subject: Reply with quote

Apprentice

Joined: 22 Jan 2013
Posts: 26

adubya wrote:
How about the following

Code:

DECLARE likeExpr CHAR 'like expression e.g. %TEST%';
SET sqlStmt = 'SELECT XXX FROM Schema.Table name WHERE XXX LIKE ?'; 
SET sqlResult = PASSTHRU(sqlStmt TO Database.dsnName VALUES (likeExpr));



Thanks! It works!!
Back to top
View user's profile Send private message
sandy vish
PostPosted: Wed Jan 23, 2013 6:51 am    Post subject: Reply with quote

Apprentice

Joined: 18 Nov 2012
Posts: 27

IF valueColumn is not null AND TRIM(valueColumn) <> '' THEN
DECLARE selectStatement CHAR;
SET selectStatement =
'select ' || valueColumn ||
' from ' || tableName ||
' where ' || keyColumn || ' = ?';
SET resultSet.values[] VALUE = PASSTHRU(selectStatement, keyValue);
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 » How to use Like clause with Values in passthru
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.