Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:19:05+00:00 2026-06-17T10:19:05+00:00

I am having a Metadata table as below: RULE_NAME COL_NAME COL_VAL RULE_1 COL_1 ABC

  • 0

I am having a Metadata table as below:

RULE_NAME      COL_NAME   COL_VAL
RULE_1     COL_1         ABC
RULE_1     COL_5         XYZ
RULE_2     COL_2         123
RULE_2     COL_3         A2d5
RULE_2     COL_8         X0IL
RULE_3     COL_1         PQR
RULE_3     COL_7         9789

I need to generate a WHERE clause using the data from this table. the WHERE clause should be like this:

WHERE
(COL_1 = 'ABC' AND COL_5 = 'XYZ') --from Rule 1 records
OR
(COL_2 = '123' AND COL_3 = 'A2D5' AND COL_8 = 'X0IL') --From Rule 2 records
OR
(COL_1 = 'PQR' AND COL_7 = '9789') --from Rule 3 records

Is this possible to do with normal SQL (I am on Teradata)? Can someone give me some pointers on how to achieve this?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:19:06+00:00Added an answer on June 17, 2026 at 10:19 am

    The following returns each of the clauses on a separate line:

    select oreplace(max(case when seqnum = 1 then clause else '' end) ||
                    MAX(case when seqnum = 2 then clause else '' end) ||
                    MAX(case when seqnum = 3 then clause else '' end)
                   ), ')(', ') and (')
    from (select t.*, ROW_NUMBER() over (partition by rule_name order by col_name) as seqnum,
                 ('(' || COL_NAME || ' = ' || '''' || col_val || ''')') as clause
          from t
         ) t
    group by rule_name
    

    Is that close enough?

    If you don’t have the ‘oreplace’ function, you can do something like:

    select max(case when seqnum = 1 then clause else '' end) ||
           MAX(case when seqnum = 2 then clause else '' end) ||
           MAX(case when seqnum = 3 then clause else '' end) || ' 1=1 OR'
    from (select t.*, ROW_NUMBER() over (partition by rule_name order by col_name) as seqnum,
                 ('(' || COL_NAME || ' = ' || '''' || col_val || ''') and') as clause
          from t
         ) t
    group by rule_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible in MSBuild to batch tasks without having the metadata value you
Having a really aggravating problem using Managed Metadata in SP2010 where I can get
I am a newbee to solr.I am having a problem with adding fields/metadata to
Im having problems with the dropbox API. When i try to get the metadata
I am using PostgreSQL database. Having a table named metadatavalue with structure is as
I have an xml having the following structure: <metadata style=basic> <zonelist> <zone name=z0 type=poster
My current project is using a metadata file to set properties without having to
Using SQLAlchemy, given tables such as these: locations_table = Table('locations', metadata, Column('id', Integer, primary_key=True),
Having a bag mapped like this: <bag name=Addresses table=address cascade=all-delete-orphan> <key column=employee/> <element column=address/>
Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.