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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic operator in query help

Author  Topic 

keyursoni85
Posting Yak Master

233 Posts

Posted - 2010-12-01 : 10:47:52
Hi i want to use operator dynamically in my query..
my data in table is like..

ID speeds speedOperator
1 52 >
3 45 >=
4 74 =
65 43 <


I want to use above table filteration like
select * from tablename where speeds [speedOperator] [someValue]

Please help it urgent. please :)

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-01 : 10:53:15
will need either dynamic sql or a lot of if statements.
Actually I think you will have to loop through the table and execute each row.
Maybe create a function to which you pass the values and return a 1 or 0?



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

keyursoni85
Posting Yak Master

233 Posts

Posted - 2010-12-01 : 12:12:00
Thanks for reply..
but isn't is any other way to achieve this dynamic operator..

please help any other way if you find...
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-12-01 : 12:15:58
I don't understand what you are trying to accomplish. You want to pass in a value, and use that value in a comparison statement that is build using the value from the speedOperator in the table, correct?

If so, I'm not sure how the data you get is going to be meaningful, as you never really know what you're going to get back.
Go to Top of Page

keyursoni85
Posting Yak Master

233 Posts

Posted - 2010-12-01 : 12:25:32
yes..
actually my comparison will be against one row..
I filter one unit's information
eg. speed = 17

then i match it with all records with specified criterias and operators
and then returns with matched criteria

It matches like below
select * from tbl_FilterCriteria
where @speed [operator] speed[table column name]
Go to Top of Page
   

- Advertisement -