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 8233179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:02:54+00:00 2026-06-07T18:02:54+00:00

I need to write a SQL query for a report. A user can select

  • 0

I need to write a SQL query for a report. A user can select six filters which are dynamic i.e. User can select one or two up to max six filters.

In each filter the user selects an attribute of a device from a dropdown, an operator and its value user needs to input. This constitutes a single filter, e.g:

     AttributeName  Operator    Value
     Cost           equal       480
AND  MappedName     contains    DummyString

Here “Cost” is attribute and “480” is the value and this whole thing consist of one filter . In Similar fashion user can select max. 6 filters
Also the operator between two filters are again dynamic . it can be “AND” or “OR”

In the report I need to dynamically generate a column for each filter along with some static columns, e.g. Device Name, Device Manufacture are static columns whereas the above filter are dynamic.

So the report when the user has selected two filters will look something like:

DeviceName   DeviceManufactur  Cost              MappedName    
D1           DM1               480               DummyString 
D2           DM2               480               DummyString  

In the database the attributes are stored something like:

 DeviceName   DeviceManufactur  AttributeName              AttributeValue
   D1           DM1               Cost                      480
   D1           DM1               MappedName               DummyString  
   D2           DM2               Cost                      480
   D2           DM2               MappedName               DummyString 

So when I write simple sql like

select d.name,d.manufacture,d.AttName,d.value
from Device d
where d.AttName='Cost' and d.AttValie='480'
    and d.AttName='MappedName' and d.AttValue='DummyString'

it will never give me any records although the device is associated with both the attributes.

Can anyone suggest any specific function of SQL which will help me in writing this logic efficiently.

  • 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-07T18:02:55+00:00Added an answer on June 7, 2026 at 6:02 pm

    I don’t think I’m really understanding your question right, but the only thing I can think of is:

    SELECT d.DeviceName, d.DeviceManufactur, d.AttributeName, d.AttributeValue
    FROM aDevice d
    WHERE d.DeviceName IN (
        SELECT dd.DeviceName
        FROM aDevice dd
        WHERE EXISTS (SELECT 1 FROM aDevice ddd WHERE AttributeName='Cost' AND AttributeValue='480' AND ddd.DeviceName = dd.DeviceName)
        AND EXISTS (SELECT 1 FROM aDevice ddd WHERE AttributeName ='MappedName' AND AttributeValue = 'DummyString' AND ddd.DeviceName = dd.DeviceName))
    

    This should return all information for any device which matches the query Cost = '480' AND MappedName = 'DummyString'…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write an SQL query to take either from one of two
I need to write a SQL query which will get me those rows from
I have two tables to track user activity: I need to write a SQL
I need to write a soql/sql query which needs to look up for a
I need to write a sql query that adds one column from one database
I have a table of products, and I need to write an SQL query
Since i'm a poor sql developer, i need support to write a sql query
I need to write a query on SQL server to get the list of
I need help with how to write a SQL Server 2005 query to handle
I need to write the following SQL statement in LINQ lambdas : SELECT *

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.