INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Teradata Dynamic Query

Teradata Dynamic Query

(OP)
Hi all,

I would like to store multiple search strings values into table or variable so I can maintain them dynamically.
Then I am going to parse them using like any.

codes are like below

CODE

-- this is expected codes which is working
    select top 10  *
    from table_main pr, table_search ms
    where pr.name like any ('%wool%','%test%'); 

Then I store the '%wool%','%test%' as a single record so I put the search strings values into table_search and it throws syntax error as per codes below

CODE

-- syntax error
    select top 10  *
    from table_main pr, table_search ms
    where pr.name like any (ms.stringname); 

Please help me how to resolve this.
Thank you,

RE: Teradata Dynamic Query

Remove the word "any", that should solve it, depending on the contents of ms.stringname.

Bye, Olaf.

RE: Teradata Dynamic Query

(OP)
Hi olaf,

For Teradata, if multiple strings we HAVE to put "any".

RE: Teradata Dynamic Query

But you don't have multiple strings in your last version, you join multiple records, one at a time.

Bye, Olaf.

RE: Teradata Dynamic Query

(OP)
yeah, but inside the column ms.stringname, it has multiple strings hence i got syntax error, I have tried it.

RE: Teradata Dynamic Query

You say stringname could be %wool%,%test% in a single row?
That won't work, a single column of a single row is a single value and can't represent a list of values in a query.

Bye, Olaf.

RE: Teradata Dynamic Query

(OP)
That's the challenge.
we need to be able to search multiple strings.

Eventhough i split up the search strings to have single row single values.

CODE

select top 10 *
    from table_main pr, table_search ms
    where pr.name like any (ms.stringname, ms.stringname1, ms.stringname2 ); 
-- won't work 

CODE

select top 10 *
    from table_main pr, table_search ms
    where pr.name like any (select ms.stringname where company = 'x' ); 
-- won't work either 

only hardcording as per sample above would work.
any other suggestions how to achieve that without hardcording?

RE: Teradata Dynamic Query

Well, if you don't post errors you get from the non working statments, and since this is a MS SQL Server forum, I fear this won't be solved here.

I don't see how your second statement could work, a subquery does not result in a list of values either.

Your first statement could work, what is the type of stringname, stringname1 and stringname2? If you don't have varchar but char there, this can't work because of trailing spaces.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close