Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kulkarni_ajit
Starting Member
4 Posts |
Posted - 2009-02-22 : 15:11:48
|
Hi, Import the table structure attached along with the data.What we are trying to achieve here is that we need to have a search which will give me group where the matching values will be available for eg. I will give search1. Location = ‘Pune’ and Year = ‘10/10/10’ Then the query should give me groups 175,1772. Location != Pune and Year =’10/10/1010’Query should return me group 1763. Location = Pune AND time = ’11:11:11’ AND Year = ‘10/10/1010’Query should return me group 1774. Company != OracleQuery should return me 179 and 180So what we are trying to do is that we are creating the table structure dynamically and the corresponding values for each column the columns are user defined.We did try using Having clause but it is not working for multiple rows ?Please let us know if you need more inputscan i do in Single SQLplease help me outRegardsajit |
|
|
SQLforGirls
Starting Member
48 Posts |
Posted - 2009-02-22 : 17:35:10
|
| This seems pretty clunky, depending on the application you will use to access the database and pass parameters, but it might be a place to start:select distinct groupfrom table1 towhere exists(select top 1 1 from table1 tiwhere ti.group = to.groupand ti.filterdesc = 'location'and ti.group_values = 'Pune')So for each of your search conditions you would have either a WHERE EXISTS or a WHERE NOT EXISTS (in the case of location != Pune). The other approach that comes to mind would be to pivot the table, and then make an input parameter (assuming you want to encapsulate this in a stored proc) for each possible filter desc. You would still need to take an input parameter for each operator as well (= or !=) and generate dynamic SQL to create the final select. |
 |
|
|
|
|
|