Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic operator in query help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

233 Posts

Posted - 12/01/2010 :  10:47:52  Show Profile  Reply with Quote
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 :)

Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 12/01/2010 :  10:53:15  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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.

Edited by - nigelrivett on 12/01/2010 10:54:24
Go to Top of Page

Posting Yak Master

233 Posts

Posted - 12/01/2010 :  12:12:00  Show Profile  Reply with Quote
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

Posting Yak Master

127 Posts

Posted - 12/01/2010 :  12:15:58  Show Profile  Reply with Quote
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

Posting Yak Master

233 Posts

Posted - 12/01/2010 :  12:25:32  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000