Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    155

    Unanswered: LET clause in combination with IN

    Hallo everyone,

    in my User Definied Function, I would like to define a variable with a LET clause:

    Code:
    LET Books = (#1#, #39#, #40#, #55#)
    In the User Defined Function, I want to check, if a String(of type VARCHAR) has at lease one book(one number in the variable Books):

    Code:
    if(Books IN myString) then 'direct'
    But it didnt work. How can I express this in SQL:
    if there is at least one of these book numbers, write 'direct'

    Thank you guys.

    Regards,
    Ratna

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Give an example of myString to make it easier to understand ..
    You may try

    Code:
    IF (LOCATE(myString,Books)>0) then direct
    It is not very clear how you get the value of Books - i mean, where it comes from.
    Also, what version of DB2 and Platform are you on?
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    May 2012
    Posts
    155
    Hallo sathyaram_s,

    thank you for the reply.

    myString is a column from type VARCHAR which looks like this:

    #1#23#39#1#678#40#

    I would like to define a variable Books like this:
    Code:
    LET Books = (#1#, #40#)

    And now, if there is at least one number from Books in myString, it should just write 'direct'. You have an idea?

    Another question:
    in my User Definied Function, I have coded this:
    Code:
    BEGIN ATOMIC
            return 
            case when(...) then 'write_something'
            end;
    END@
    It run succesfully. But this one went wrong:
    Code:
    BEGIN ATOMIC
            return 
            if(...) then 'write_something'
            end if;
    END@
    Does it have something to do with BEGIN ATOMIC or return?

    Thank you..

    Regards,
    Ratna

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •