If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > String function "IN" with dynamic arguments

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-29-08, 16:16
prem18 prem18 is offline
Registered User
 
Join Date: Apr 2007
Posts: 51
Question String function "IN" with dynamic arguments

can you suggest of the ways for me to do string existence check against a table field

eg:

sal_type IN ( 'S','R',...<dynamic list>)

the number of arguments in the parenthesis is not fixed and may vary at run time

i.e. if the sal_type matches with any of the listed characters, then --> output stmts

any quick suggestion would be really helpful
__________________
*** Prem ***
Oracle Certified Associate - SQL & PL/SQL
Reply With Quote
  #2 (permalink)  
Old 10-29-08, 17:00
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You have two choices. Build the SQL statement dynamically and set the entire list by appending the items on. This can get ugly. Second, Put the values in a temp table and then use "where x in (select y from temptable)".

Andy
Reply With Quote
  #3 (permalink)  
Old 10-29-08, 23:37
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
> sal_type IN ( 'S','R',...<dynamic list>)
LOCATE(sal_type, 'S,R,' || <dynamic list>) > 0
Reply With Quote
  #4 (permalink)  
Old 10-31-08, 01:14
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
It also depends upon from where you are getting your dynamic list from....
If you can get it from the DB itself you can very well use a sub-query
OR
If you are getting it from application OR if you are getting it from application + DB then you can very well try out dynamic SQL statements. (All that you do in this case is store the SQL statement in a VARCHAR and then execute the same)
Reply With Quote
  #5 (permalink)  
Old 10-31-08, 09:57
prem18 prem18 is offline
Registered User
 
Join Date: Apr 2007
Posts: 51
Thumbs up

yes. thank u so much. I am done with my processing with these helpful suggestions!
__________________
*** Prem ***
Oracle Certified Associate - SQL & PL/SQL
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On